1. Check the my.cnf to see if there is a password ... That's one of those, isn't it?
2. If you can restart,
First use the –skip-grant-tables parameter restart, and then change the password, and then remove the –skip-grant-tables parameter restart, pay attention to –skip-grant-tables security problems http://code.openark.org/ Blog/mysql/dangers-of-skip-grant-tables, according to the Fire Ding notes http://huoding.com/2011/06/12/85, also need to add--skip-networking
$ mysqld_safe--skip-grant-tables--skip-networking &
After using the SQL Reset password, remember to remove the skip-networking and restart the MySQL service in the normal way:
$/etc/init.d/mysqld Restart
The above method needs to restart the service two times, in fact, it can be more elegant, reboot once: the first need to save the SQL statement used in a text file (/path/to/init/file):
UPDATE mysql.user SET password=password (' ... ') WHERE user= ' ... ' and host= ' ... ';
FLUSH privileges;
Then use the Init-file parameter to start the MySQL service,
$/etc/init.d/mysql Stop
$ mysqld_safe--init-file=/path/to/init/file &
At this point, the password has been reset, and finally do not forget to delete the contents of the file, so as not to disclose the password.
3.on Linux/unix only
$ CD Data/mysql
$ CP-RP user. MYD Bck_user. Myd_ ' Date +%y%m%d ' CP-RP user. Myd/tmp/user. MYD
$ vi/tmp/user. MYD # (Edit the hashed passwords next to root*) Cp-rp/tmp/user. MYD user. MYD
$ sudo kill-hup ' pidof mysqld '
4.using an Init-file
4. There is also a 4th using a init-file, which leads to just one restart of the database instead of two. It also avoids the security issue involved with using Skip-grant-tables.
5. If you are in MySQL, there are too many options.
Reference
MySQL root Password Loss Resolution summary