How To Reset The Root Password On Mysql

You can recover a MySQL database server password with the following four easy steps:

Step 1: Stop the MySQL server process.
Step 2: Create a text file containing the password-assignment statement on a single line, example;

        /*** MySQL 5.7.6 and later ***/
        ALTER USER 'root'@'localhost' IDENTIFIED BY 'TheNewPass';

        /*** MySQL 5.7.5 and earlier ***/
        SET PASSWORD FOR 'root'@'localhost' = PASSWORD('TheNewPass');      

Save the file, example /usr/mysql/my_file.sql

Step 3: Start the MySQL server with the special –init-file option, example;

 mysqld_safe --init-file=/usr/mysql/my_file.sql &

The server executes the contents of the file named by the –init-file option at startup

Step 4: Stop the server and restart it normally.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s