Method uses the Reset script
| The code is as follows |
Copy Code |
wget Http://xxxx/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.
Using Mysqladmin
| The code is as follows |
Copy Code |
#./mysqladmin-u root password ' newpassword ' #./mysqladmin-u root-h host_name password ' newpassword ' Usually mysqladmin ' s path is/usr/bin, HOST_NAME is your real host name, e.g. Localhost.localdomain. |
The quotes behind the password are not required, but quotation marks are required if the password contains spaces or some special symbols.
Using the MySQL SET password command
| The code is as follows |
Copy Code |
#./mysql-u Root mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' NewPassword '); mysql> SET PASSWORD for ' root ' @ ' host_name ' = PASSWORD (' NewPassword '); |
Update the user table with the UPDATE statement reset root password
| The code is as follows |
Copy Code |
#./mysql-u Root mysql> UPDATE mysql.user SET Password = Password (' newpassword ') WHERE user = ' root '; mysql> FLUSH privileges; |
Manual modification
1. Stop MySQL Service
Execution:/etc/init.d/mysql stop, not necessarily on your machine/etc/init.d/mysql may also be/etc/init.d/mysqld
2, skip verification to start MySQL
/usr/local/mysql/bin/mysqld_safe--skip-grant-tables >/dev/null 2>&1 &
Note: If the location of the Mysqld_safe is not the same as the above need to be modified to your, if not clear can be found with the Find command.
3. Reset Password
Wait a minute and then execute:/usr/local/mysql/bin/mysql-u root MySQL
When the MySQL prompt appears, enter: Update user Set password = password (' Password to set ') where user = ' root ';
After carriage return carries out: flush privileges; Refresh the MySQL system permissions related tables. Re-execution: exit; Exit.
4, restart MySQL
Kill MySQL Process: Killall mysqld
Restart Mysql:/etc/init.d/mysql start