MySQL database root password loss problems

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44297303/article/details/96605027

Problem: Missing super user password, no access to the database:

#./mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

Here Insert Picture Description

Forced to quit database

# ps -ef | grep mysql

Here Insert Picture Description

# kill -9 44184 43251

Plus skip the permissions table parameters, restart the database

  • Plus --skip-grant-tables parameter permission table may be skipped
# ./mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
# ./mysql		#不用密码,也能进入数据库

Here Insert Picture Description

Set a new password to the root user privileges and refresh

root@localhost [(none)]>use mysql;
root@localhost [mysql]>update user set authentication_string=password('root') where user='root';
root@localhost [mysql]>flush privileges;
  • password ( 'password'), is the first root password
    Here Insert Picture Description

The previous mysql process kill off, and then you can re-login

# ./mysqld_safe --defaults-file=/etc/my.cnf &
# ./mysql -uroot -proot

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44297303/article/details/96605027