The root user of mysql in linux can't log in record

can't log in.

Access denied for user ‘root’@’localhost’ (using password:YES)

root User can't log in reason

1, your root password is forgotten, the password is wrong, all can't log in. 2, set the access rights of root, for example, ip wrote a non-existent (this is guessing, because I remember I only changed the access rights, the password is certainly not wrong.)

解方法

1, stop mysql

service mysqld stop

2, start mysql installation mode

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &This means I really don't understand, --user should mean The user who starts, the & symbol is the meaning of running in the background. Some people use the following command, generally you can try both.
Mysqld--user=root --skip-grant-tables

3, reconnect mysql

mysql -uroot -p // No password is required here, because it is safe mode.  After entering mysql, it is to change the password.
Mysql>use mysql; // first switch to the mysql library. mysql> update user set password=passworD("123456") where user='root';
mysql> flush privileges;
mysql> exit;

Then you can log in with the new password.