mysql> use mysql
ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘mysql’
Solution:
# mysqld_safe –skip-grant-table
161104 10:36:00 mysqld_safe Logging to ‘/var/log/mysqld.log’.
161104 10:36:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
At this point the terminal is in a waiting state, open another terminal to change the root password of mysql
# mysql -u root
mysql> update user set password=PASSWORD(”) where user=’root’; # Here I set the root password to null
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3 Changed: 0 Warnings: 0
mysql> delete from user where user=”; # Delete this ”@’localhost” user, otherwise it will still default to this user after login
Query OK, 2 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
After changing the root password of mysql, stop the mysqld service, at this point, the above terminal will stop waiting.
# /etc/init.d/mysqld restop
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
The problem is solved by logging into mysql again.