Changing a forgotten MySQL root password

To change the MySQL root password, use the following steps:

  1. Run the following commands:

    # /etc/init.d/mysqld stop
    
    # mysqld_safe --skip-grant-tables --skip-networking
    
  2. Connect to MySQL with the following command:

    # mysql -u root
    
  3. Run the following command in the MySQL client:

    # UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
    
  4. Replace newpassword with your new root password.

  5. Restart the MySQL server by using the following command:

    # /etc/init.d/mysqld start