"show databases" doesn't show databases - mysql

I have the following DBs visible in phpmyadmin:
but when I type the command show databases; it doesn't show all of them:
sudo mysql -u root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
+--------------------+
4 rows in set (0.00 sec)
Why is this happening?

When you type SHOW DATABASES it only shows you the databases the current user has access to.

Related

Cannot grant privileges to a user on a database

I'm baffled by the problem I'm having. I created a database, created a user, and want to grant the user all privileges on the database. One way or another, I'm having syntax errors, while I'm fairly sure there is no syntax error.
MariaDB [(none)]> SELECT User FROM mysql.user;
+------------+
| User |
+------------+
| osticket |
| phpmyadmin |
| root |
+------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| osticket |
| performance_schema |
| phpmyadmin |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON 'osticket'.* TO 'osticket'#localhost;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''osticket'.* TO 'osticket'#localhost' at line 1
MariaDB [(none)]>
I also changed localhost to 'localhost' to be sure, no avail. What's going on here?
GRANT ALL PRIVILEGES ON `osticket`.* TO 'osticket'#localhost;
be aware of the quotations
`osticket`.*

MariaDB on Docker Linux have two different version between external/internal IP

I ran MariaDB as Docker - expose port 3306 to localhost:3307
Connect Database via localhost:3307
$ mysql -u tvgift -P 3307 -h localhost -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
Connect Database via 172.18.0.2:3306 (IP I got from $ docker inspect <docker ID>
$ mysql -u tvgift -P 3306 -h 172.18.0.2 -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set (0.00 sec)
I tried another client (Using mycli) with both IP, result is same.
$ mycli mysql://tvgift:tvgift#localhost:3307/tvgift
mariadb tvgift#localhost:tvgift> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set
Time: 0.013s
$ mycli mysql://tvgift:tvgift#172.18.0.2:3306/tvgift
mariadb tvgift#172.18.0.2:tvgift> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set
Time: 0.013s
So, only mysql client have differ between two IP of one container service, can you tell me why?
localhost != any IP address. That is,
GRANT ... TO tvgift#'%' ...
does not include
GRANT ... TO tvgift#'localhost' ...
If you want to connect both via localhost and via an IP address or hostname, you must provide two GRANTs with the same permissions (such as ON tvgift.*).

Mysql error (42000) Unknown database 'testdb' while trying to connect to mysql remotely from another machine

Dears ,
I have two Virtual machines App1 & db ...
I installed Mysql in db machine , and I am trying on App1 machine to build EAR for springboot-demo-app following steps in this link (https://github.com/Mhussein27/springboot-demo-app)
But I am stuck in the step (mvn package) on app1 machine after exporting Mysql Configuration like the below , I am facing Unknown database error :
export APP_DATABASE_USER=testuser
export APP_DATABASE_PASSWORD=XXX
export APP_DATABASE_URL='jdbc:mysql://db:3306/testdb'
admin#app1:~/springboot-demo-app$ mvn package
Error:
Unable to obtain database connection
------------------------------------
SQL State : 42000
Error Code : 1049
Message : Unknown database 'testdb'
on db machine I can see the testuser and the testdb schema and privileges are fine !
mysql> SELECT User,Host FROM mysql.user;
+---------------+-----------+
| User | Host |
+---------------+-----------+
| testuser | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql> SHOW GRANTS FOR 'testuser'#'%';
+------------------------------------------------------+
| Grants for testuser#% |
+------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'testuser'#'%' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'testuser'#'%' |
+------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show tables;
+-----------------------+
| Tables_in_testdb |
+-----------------------+
| flyway_schema_history |
+-----------------------+
1 row in set (0.00 sec)
Please let me know what is wrong !!

There is a way to import database files(.MYD .MYI) in mysql8?

In mysql5.7 I can copy whole folder of a database when I want to backup it.
I mistook can do this in Mysql8.0.So I didn't do anyting when I reinstall the system.
Now I use "show databased":
mysql> show databases \g
+--------------------+
| Database |
+--------------------+
| blog |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
It didn't display old database "blog2" but blog2 folder is there.
here is screenshot my disk

mysql show databases() only information_schema database

I use mysql -u root -p to login to mysql. Command show databases only shows information_schema database, and current_user is not root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
2 rows in set (0.00 sec)
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| #localhost |
+----------------+
1 row in set (0.00 sec)
You have no other databases - try to create one.
The current user is probably the anonymous user - by default MySQL ships with the following users, all having empty password (https://dev.mysql.com/doc/refman/5.5/en/default-privileges.html)