Resetting MySQL root user password
Complete the following steps if you need to reset your MySQL root user password:
- Take down the
mysqld
server by sending akill (not kill -9)
to themysqld
server. 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
mysqld
with the--skip-grant-tables
option. - Connect to the
mysqld
server.- Option 1:
mysql -h hostname mysql
and change the password with a GRANT command. - For more information about GRANT commands, see MySQL 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-privileges
or 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.