IBM Cloud Docs
Resetting MySQL root user password

Resetting MySQL root user password

Complete the following steps if you need to reset your MySQL root user password:

  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:
    • 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.
  2. Restart mysqld with the --skip-grant-tables option.
  3. 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'
  4. Load the privilege tables by using shell> mysqladmin -h hostname flush-privileges or with the SQL command mysql> 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.