How to reset a mySQL password?

If you have lost your root user password for MySQL, you can reset it with the following procedure:

  1. Take down the mysqld server by sending a kill (not kill -9) to the mysqld server. The pid is stored in a .pid file, which is normally in the MySQL database directory:
    Example: shell> kill `cat /your-mysql-data-directory/hostname.pid`
    In Red Hat you can also stop the databse with:
    Example: shell> service mysqld stop
    You must be either the Unix root user or the same user the server runs as to do this.
  2. Restart mysqld with the --skip-grant-tables option.
  3. Connect to the mysqld server with
    Option 1:mysql -h hostname mysql and change the password with a GRANT command.
    See MySQL website: MySQL: 7.35 GRANT and REVOKE Syntax
    Option 2: shell> mysqladmin -h hostname -u user password 'new password'
  4. Load the privilege tables with: "shell> mysqladmin -h hostname flush-privileges” or with the SQL command "mysql> FLUSH PRIVILEGES;".


Note: Note that after you started mysqld with --skip-grant-tables, any usage of GRANT commands will give you an Unknown command error until you have executed FLUSH PRIVILEGES.

  • 7 Users Found This Useful
Was this answer helpful?

Related Articles

MySQL Optimization / Repair Information

How MySQL Uses MemoryThis page lists some of the ways that the mysqld server uses memory, and...

How can I monitor what my MySQL server is doing?

A handy little Linux application called mytop fits this just perfectly. This is a near-time...

How do I backup MySQL in Linux?

1. Copying from the mysql directoryBy default, MySQL databases on servers that use Linux are...

Repairing MySQL tables that will not open

This should be handled on a case by case basis, but if you are using the default MySQL table type...

Securing MySQL

Due to differing needs and requirements this is difficult to answer except on a case by case...