ArticleSource: http://www.centos.bz/2011/04/reset-mysql-root-password/
Follow these steps to reset the password of the MySQL database server. Step 1: Stop the MySQL server. Step 2: Use-Skip-grant-tables to select to start the mysqld process to cancel the Logon Request password prompt. Step 3: Use the root user to connect to the MySQL server. Step 4: set a new MySQL Root User Password. Step 5: exit and restart the MySQL server. The following are the specific commands for each step.
1. Stop the MySQL Service
- /Etc/init. d/MySQL stop
Output:
Stopping MySQL database server: mysqld.
2. Set the ignore password to start the MySQL server
- Mysqld_safe -- skip-grant-tables &
Output:
[1] 5988
Starting mysqld daemon with databases from/var/lib/MySQL
Mysqld_safe [6025]: started
3. Use the mysql client to connect to the MySQL server
- Mysql-u Root
Output:
Welcome to the MySQL monitor. commands end with; or G.
Your MySQL connection ID is 1 to server version: 4.1.15-Debian_1-log
Type 'help; 'or 'H' for help. Type 'C' to clear the buffer.
Mysql>
4. Set a new MySQL Root User Password
- Mysql> use MySQL;
- Mysql> Update user SET Password = PASSWORD ("new-root-Password") where user = 'root ';
- Mysql> flush privileges;
- Mysql> quit
5. Stop the MySQL server
- /Etc/init. d/MySQL stop
Output:
Stopping MySQL database server: mysqld
Stopping server from PID file/var/run/mysqld. PID
Mysqld_safe [6186]: ended
[1] + done mysqld_safe-Skip-grant-tables
6. Start and test the MySQL server.
- /Etc/init. d/MySQL start
- Mysql-u root-P