1. Problem description
Newly installed MySQL, unable to log in using phpMyAdmin, reported:
1 | ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) |
2. Solution
2.1, configure password-free login
In the configuration file my.cnf
add:
1 | skip-grant-tables |
Then restart MySQL:
1 | /etc/init.d/mysqld restart |
2.2, delete empty users
implement:
1 | mysql -uroot -p<password> |
Change <password>
to the root password, log in to the MySQL command line, and execute:
1 | USE mysql; Delete FROM user Where User='' and Host='localhost'; FLUSH PRIVILEGES; |
2.3, set permissions
If MySQL 5.6 and below:
1 | UPDATE mysql.user set password=password('root <password>') WHERE user='root' AND host='localhost'; FLUSH PRIVILEGES; |
<password>
to root password.
If MySQL 5.7 and above:
1 | update user set authentication_string='' where user='root'; ALTER user 'root'@'localhost' IDENTIFIED BY '<password>'; FLUSH PRIVILEGES; |
<password>
to root password.
2.4, close password-free login
In my.cnf
delete
1 | skip-grant-tables |
Restart the database:
1 | /etc/init.d/mysqld restart |
Fix Cannot Log in MySQL via Password
Comments