[root@ mysql]# mysql -uroot -p
Enter password:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
mysql> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
修改mysql.cnf添加skip-grant-tables重启mysql,使用mysql -uroot -p登录,
mysql> use mysql;
Database changed
mysql> select user,host,password from mysql.user;
+---------+-----------+-------------------------------------------+
| user | host | password |
+---------+-----------+-------------------------------------------+
| root | % | *D81B33CC1B726D16150CE13746F41C6B99FEACCD |
| root | ebs-58375 | *D81B33CC1B726D16150CE13746F41C6B99FEACCD |
| root | 127.0.0.1 | *D81B33CC1B726D16150CE13746F41C6B99FEACCD |
| | localhost | |
| | ebs-58375 | |
| db_root | % | *5717FA01773A351D634EA0E0F972EE8900960C3F |
+---------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)
发现两个空用户,密码也是空的,将其删除后刷新权限
mysql>delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+---------+-----------+-------------------------------------------+
| user | host | password |
+---------+-----------+-------------------------------------------+
| root | % | *D81B33CC1B726D16150CE13746F41C6B99FEACCD |
| root | ebs-58375 | *D81B33CC1B726D16150CE13746F41C6B99FEACCD |
| root | 127.0.0.1 | *D81B33CC1B726D16150CE13746F41C6B99FEACCD |
| db_root | % | *5717FA01773A351D634EA0E0F972EE8900960C3F |
+---------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)