Reasons and solutions for MySQL root users unable to log in

MySQL root password is correct, but bai cannot log in locally. MySQL
login prompt
ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: YES) The
possible cause is the user table of bai in the mysql library There is no data item that root points to host: localhost, and there is only one data item that root points to host: host name, so it is impossible to log in to MySQL with the root account.
Solution
1. Kill the MySQL process first.
2. Add --skip-grant-tables to the parameter of starting mysql. Now
you can log in to mysql without a password.
3. Fix the lost data items of the root account.
There are two solutions:
  
The first is because the root account initially has 3 records, including root corresponding to localhost, hostname, and 127.0.0.1. We can update host to localhost in one of the other two.
  
The second is to insert a record directly, the host is localhost, so
  even if the root host contains the host name, 127.0.0.1 still cannot log in normally, and there must be a localhost host.
  
If the above method still fails to log in normally, we can try another method
to enter mysql with the mysql command directly and enter mysql, but there are only test and information_schema databases, no mysql and other databases. Use mysql to report the following error:
mysql> use mysql
  ERROR 1044 (42000): Access denied for user "@'localhost' to database'mysql'
  means that there is no user specified and no permission to access the database mysql.
  Then log in as root, enter the correct password and report the following error:
  [root@ 228827 ~]# mysql -uroot -p123456
  ERROR 1045 (28000): Access denied for user'root '@'localhost' (using password: YES) If the
  password is correct, the mysql database has forbidden the root user's local login authority Up

Guess you like

Origin blog.51cto.com/14483703/2546111