mysql show databases() only information_schema database - mysql

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)

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`.*

"show databases" doesn't show databases

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.

mysql showing different number of databases

This is from my terminal in mac.
130-229-0-129-dhcp:~ suyeshamatya$ mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
mysql> quit
Bye
130-229-0-129-dhcp:~ suyeshamatya$ mysql -u root -p
Enter password:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| lportal |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
Can someone please explain why mysql is showing different number of databases when connecting without any username/password and when connecting with root username/password?
UPDATE:
Connected without username/password
mysql> show grants;
+--------------------------------------+
| Grants for #localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''#'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)
Connected with root username/password
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '********************' WITH GRANT OPTION |
| GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Grant USAGE means no privileges for that user according to Manual. So when you login without username and password. It will show default mysql schema. If you want to user using following query:
select User from mysql.user;
It will throw error like
SELECT command denied to user ''#'localhost' for table 'user';
Which means you do not have permission on default database to view users details.
If you login with username and password then all the databases created by that User will show you.
I am not sure but I think that the the "unknown user" has no privileges to see the other databases. Please check this in the mysql database.

Cannot see the created database in mysql

I created a database from the mysql prompt. It is named "spring_security_tutorial".
Then, I created a user named "erdinc#localhost" and granted the user all the privileges for the "spring_security_tutorial" db.
Here is the "show databases" result when I am connected as root:
mysql> show databases;
+--------------------------+
| Database |
+--------------------------+
| information_schema |
| mysql |
| performance_schema |
| spring_security_tutorial |
| springsecurity |
| test |
+--------------------------+
6 rows in set (0.00 sec)
Here is the result of the command "use spring_security_tutorial" when I am connected as root:
mysql> use spring_security_tutorial;
ERROR 1049 (42000): Unknown database 'spring_security_tutorial'
Here is the result of the command "select user(), current_user()":
mysql> select user(), current_user()
+----------------+----------------+
| user() | current_user() |
+----------------+----------------+
| root#localhost | root#localhost |
+----------------+----------------+
1 row in set (0.00 sec)
Here are the privileges of the root and erdinc users:
mysql> show grants for 'root'#'localhost';
+---------------------------------------------------------------------+
| Grants for root#localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for 'erdinc'#'localhost';
+---------------------------------------------------------------------------------------------------------------+
| Grants for erdinc#localhost |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'erdinc'#'localhost' IDENTIFIED BY PASSWORD '*8DCDD69CE7D121DE8013062AEAEB2A148910D50E' |
| GRANT ALL PRIVILEGES ON `spring_security_tutorial`.* TO 'erdinc'#'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
I cannot use the spring_security_tutorial database as root user even if I can see it with "show databases".
Also, when I am connected as "erdinc#localhost", I cannot even show the mentioned database.
It just shows the test and information_schema databases.
I am looking up for this for a couple of hours now. Actually I used to use mysql in the past, either something changed in the usage or I am missing something very obvious because this used to be a trivial task.
Thanks in advance.

MySQL appears to DROP USER; but user still exists in mysql.users table

I've just installed MySQL Community server (5.5.8) on Mac OS X 10.6.6.
I've been following the rules for a secure install (assign password to root, delete anonymous accounts, etc), however, there is one user account which I can't DROP:
mysql> select host, user from mysql.user;
+--------------------------------+------+
| host | user |
+--------------------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| My-Computer-Hostname.local | |
| My-Computer-Hostname.local | root |
| localhost | root |
| localhost | web |
+--------------------------------+------+
6 rows in set (0.00 sec)
mysql> drop user ''#'My-Computer-Hostname.local';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user from mysql.user;
+--------------------------------+------+
| host | user |
+--------------------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| My-Computer-Hostname.local | |
| My-Computer-Hostname.local | root |
| localhost | root |
| localhost | web |
+--------------------------------+------+
6 rows in set (0.00 sec)
mysql>
As you can see, MySQL reports no errors when executing the DROP USER command, but doesn't actually delete the user!
I've tried also deleting the user from within phpMyAdmin (3.3.9) and that produced the same results (i.e. reported success, no error messages, user not deleted).
I've researched this and some people suggest that GRANT may be blocking the DROP USER command, however, the user has no GRANT privileges:
mysql> SHOW GRANTS FOR ''#'My-Computer-Hostname.local';
+-----------------------------------------------------------+
| Grants for #my-computer-hostname.local |
+-----------------------------------------------------------+
| GRANT USAGE ON *.* TO ''#'my-computer-hostname.local' |
+-----------------------------------------------------------+
1 row in set (0.00 sec)
mysql> REVOKE GRANT OPTION ON *.* FROM ''#'My-Computer-Hostname.local';
ERROR 1141 (42000): There is no such grant defined for user '' on host 'my-computer-hostname.local'
I tried dropping the user again after that but it didn't drop/delete the user either.
I've checked my MySQl error logs and there's nothing unusual in there.
The MySQL manual suggests that it is possible to delete all anonymous accounts, so why can't I delete this one?
Or, to delete just the anonymous one and not the root as well:
mysql> DELETE FROM mysql.user WHERE User='' AND Host='my-computer-hostname.local';
Worked for me on 5.1.57.
This is a known bug due to your uppercase characters: http://bugs.mysql.com/bug.php?id=62255
Use the suggestion from user douger as a workaround
You can still delete the records from the user table:
mysql> DELETE FROM user WHERE host='my-computer-hostname.local';
Query OK, 2 rows affected (0.00 sec)
This method was used prior to MySQL 4.1...
MySQL includes an anonymous user account that allows anyone to connect into the MySQL server without having a user account. This is meant only for testing, and should be removed before the database server is put into a production environment.
Run the following SQL script against the MySQL server to remove the anonymous user account:
DELETE FROM mysql.user WHERE User='';
After making changes to permissions/user accounts, make sure you flush the provilege tables using the following command:
FLUSH PRIVILEGES;