Resetting MySQL root user password
Complete the following steps if you need to reset your MySQL root user password:
- Take down the
mysqldserver by sending akill (not kill -9)to themysqldserver. The PID is stored in a .pid file, which is normally in the MySQL database directory:shell> kill cat /your-mysql-data-directory/hostname.pid- In Red Hat, you can also stop the database.
shell> service mysqld stop- You must be either the UNIX root user or the same user the server runs as to stop the database.
- Restart
mysqldwith the--skip-grant-tablesoption. - Connect to the
mysqldserver.- Option 1:
mysql -h hostname mysqland change the password with a GRANT command. - For more information about GRANT commands, see Documentation.
- Option 2:
shell> mysqladmin -h hostname -u user password 'new password'
- Option 1:
- Load the privilege tables by using
shell> mysqladmin -h hostname flush-privilegesor with the SQL commandmysql> FLUSH PRIVILEGES;.
After you start mysqld with --skip-grant-tables, any usage of GRANT commands returns an Unknown command error until you run FLUSH PRIVILEGES.