If you forget the password for MySQL
1. Turn off the MySQL service
[[Email protected] ~]# service mysqld stop
2. Modify the service startup script, add--skip-grant-tables--skip-networking field skip authorization table and network
[Email protected] ~]# Vim/etc/init.d/mysqld
Case ' $mode ' in
' Start ')
# Start Daemon
# Safeguard (relative paths, core dumps ...)
CD $basedir
Echo $echo _n "Starting MySQL"
If Test-x $bindir/mysqld_safe
Then
# Give extra arguments to mysqld with the my.cnf file. This script
# May is overwritten at next upgrade.
$bindir/mysqld_safe--skip-grant-tables--skip-networking--datadir= "$datadir"--pid-file= "$mysqld _pid_file_path
"$other _args >/dev/null 2>&1 &
Wait_for_pid created "$!" "$mysqld _pid_file_path"; Return_value=$?
3. Start the service, connect MySQL, no need to enter the password
4. Change the root password, prompt to skip the authorization form cannot change the password, so you can only change the file
mysql> SET PASSWORD for ' root ' @ ' localhost ' =password (' 123456 ');
ERROR 1290 (HY000): The MySQL server is running with the--skip-grant-tables option so it cannot execute this statement
mysql> UPDATE user SET Password=password (' 123456 ') WHERE user= ' root ';
Query OK, 3 Rows Affected (0.00 sec)
5. After the password change is complete, turn off the MySQL service, modify the MySQL startup script, start the MySQL service
6. The client can log in to MySQL using the new password.
This article from "Plum blossom fragrance from bitter cold" blog, please be sure to keep this source http://wangjunkang.blog.51cto.com/8809812/1586081
MySQL password forgot how to handle