Problem phenomenon:
Error message:
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 或
ERROR 1045 (28000): Access denied for user 'roort'@'localhost' (using password: YES)
cause of issue:
In the user table of the mysql database, there are accounts with empty user names, that is, anonymous users. As a result, although root is used when logging in , it is actually logged in anonymously. It can be seen through the error prompt ''@'localhost' .
Solution:
1. Stop the mysqld service
[root@Paul ~]# service mysqld stop
2. Add a skip-grant-tables line to the configuration file /etc/my.cnf to skip password verification
[root@Paul ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
user=mysql
log-bin=mysql-bin
basedir=/usr/local/mysql
skip-grant-tables // 添加skip-grant-tables
3. Start the mysqld service and enter in the newly opened terminal
[root@Paul ~]# mysql
mysql> use mysql;
mysql> select user from user;
+------+
| user |
+------+
| root |
| root |
| root |
| |
| |
| root |
6 rows in set (0.00 sec)
You can see that there are 2 anonymous accounts with empty usernames
mysql> delete from user where user='';
Query OK, 2 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4. Delete skip-grant-tables in the configuration file /etc/my.cnf