Article structure diagram:
1. MYSQL5.6 password lost
1. Forcibly stop MYSQL
Losing the password of the super administrative user ROOT is fatal, and the permission table can be skipped by the --skip-grant-tables parameter.
Stop MYSQL and forcibly kill the process.
kill -9 2311 3068
ps -ef | grep mysql
2. Skip permissions to start the database
/usr/local/mysql5.6/bin/mysqld_safe --defaults-file=/etc/my3306.cnf --skip-grant-tables &
3. Modify the ROOT user password
Login to the database:
mysql -S /tmp/mysql3306.sock
change Password:
update mysql.user set password=PASSWORD('mysql01') where User='root'; --5.6 Modify the statement
update mysql.user set authentication_string=password('mysql01') where user='root'; --5.7 Modify the statement
flush privileges;
4. Restart the database test
Forcibly close the database:
ps -ef | grep mysql
kill -9 3131 3794
Start the database normally:
/usr/local/mysql5.6/bin/mysqld_safe --defaults-file=/etc/my3306.cnf &
Test login:
Successfully modified.
2. MYSQL5.7 password lost
1. Forcibly stop MYSQL
Similarly 5.6
Forcibly stop the database:
ps -ef | grep mysql
kill -9 2123 3430
ps -ef | grep mysql
2. Skip permissions to start the database
/usr/local/mysql5.7/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --skip-grant-tables &
3. Modify the ROOT user password
Login and change password:
mysql -S /tmp/mysql3307.sock
update mysql.user set password=PASSWORD('mysql01') where User='root'; --5.6 Modify the statement
update mysql.user set authentication_string=password('mysql01') where user='root'; --5.7 Modify the statement
flush privileges;
4. Restart the database test
Forcibly close the database:
ps -ef | grep mysql
kill -9 4028 5354
Start the database normally:
/usr/local/mysql5.7/bin/mysqld_safe --defaults-file=/etc/my3307.cnf &
Test login:
mysql -S /tmp/mysql3307.sock -uroot -p'mysql01'
Note that under normal circumstances it is modified like this:
set password for 'root'@'localhost'=password('mysql');