If you accidentally forget the root password, or as I do wrong operation of the root permissions to the minimum, you do not have to panic, use the following steps to easily retrieve the password:
Method One
1. Run MySQL in safe mode and skip security verification
/usr/bin/mysqld_safe--skip-grant-tables
2, as root login MySQL
The code is as follows |
Copy Code |
/usr/bin/mysql-uroot |
3, reset, empty the root password
The code is as follows |
Copy Code |
mysql> use MySQL; mysql> Update user set password= ' where user= ' root '; |
4. Reset Password to root
The code is as follows |
Copy Code |
/usr/bin/mysqladmin-uroot password ' Your password here ' |
Method Two
using the Reset script
The code is as follows |
Copy Code |
wget Http://soft.vpser.net/lnmp/ext/reset_mysql_root_password.sh;sh reset_mysql_root_password.sh |
Suitable for LNMP or MySQL admin scripts in/etc/init.d/mysql and MySQL installed in/usr/local/mysql/. Otherwise, you will need to modify the script before performing the SH reset_mysql_root_password.sh.