Resetting ROOT password in MySQL 5.6

痴心易碎 提交于 2019-11-27 07:28:08

On Windows:

0) shut down service mysql56

1) go to C:\ProgramData\MySQL\MySQL Server 5.6, note that ProgramData is a hidden folder

2) looking for file my.ini, open it and add one line skip-grant-tables below [mysqld],save

[mysqld]

skip-grant-tables

3) start service mysql56

4) by right, you can access the database, run mysql

5) and use the query below to update the password

update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';

note: for newer version, use authentication_string instead of password

6) shut down the service again, remove the line skip-grant-tables save it, and start the service again. try to use the password you set to login.


On Mac:

0) stop the service

sudo /usr/local/mysql/support-files/mysql.server stop

1) skip grant table

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

once it's running, don't close it, and open a new terminal window

2) go into mysql terminal

/usr/local/mysql/bin/mysql -u root

3) update the password

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

for newer version like 5.7, use

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';

4) run FLUSH PRIVILEGES;

5) run \q to quit

6) start the mysql server

sudo /usr/local/mysql/support-files/mysql.server start
  • Stop Mysql service by going into Administrative tools > Services
  • Open Start > Run > cmd (Run as administrator)
  • Start the server manually using this line:

    mysqld -P3306 --skip-grant-tables
    
  • In new cmd (Run as administrator) execute :

    mysql -P3306 mysql
    
  • Execute the following query in mysql client:

    update mysql.user set authentication_string=password('new_password') where user='root';
    

That's it!!

The issue has been resolved.

As stated in my question I followed instructions from MySQL manual.

The process did not go exactly as described (and this was the reason for my original post) but it worked nevertheless (see UPDATE section in my post).

Polyakoff

Updating this answer regarding to changes at MySQL 5.7:

0) shut down service mysql57

1) go to C:\ProgramData\MySQL\MySQL Server 5.7, note that ProgramData is a hidden folder

2) looking for file my.ini, open it and add one line skip-grant-tables below [mysqld],save

[mysqld]

skip-grant-tables

3) start service mysql57

4) by right, you can access the database, run mysql

5) and use the query below to update the password

update mysql.user set authentication_string=password('NEW_PASSWORD') where user='root';

6) shut down the service again, remove the line skip-grant-tables save it, and start the service again. try to use the password you set to login.

In case if you have Xampp installed.

  1. Goto C:\xampp\mysql\bin
  2. Open my.ini file
  3. Put skip-grant-tables under [mysqld]
  4. Goto windows services and stop mysql service
  5. Trigger this command from command prompt C:\xampp\mysql\bin\mysql
  6. Now, reset the root password with the MySQL query update mysql.user set password=PASSWORD('root') where user='root';
  7. Exit the command prompt.
  8. Restart the mysql windows service that was turned off in step 4.
  9. Now you will be able to login to mysql using password as root.
Mohan

For MySQL 5.6 on Windows I had to run this statement to make it work.

UPDATE mysql.user
SET Password=PASSWORD('NEW PASSWORD'), 
authentication_String=PASSWORD('NEW PASSWORD')
WHERE User='root';

Without editing mi.ini:

service mysql stop
mysqld_safe --skip-grant-tables

on a separate ssh session:

update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';

no need to flush privileges, just restart the server

First stop mysql server and follow below steps:

Go to mysql bin directory on cmd i,e. cd C:\ProgramData\MySQL\MySQL Server 5.6\bin (Its a hidden directory)

skip grant tables will allow you enter into mysql

  • mysqld.exe --skip-grant-tables

Open new command prompt or on same command prompt

  • mysql.exe -uroot -p (without any password you can login to mysql)

run below query to change mysql root password

  • UPDATE mysql.user set password=password('root password') WHERE user='root';
  • flush privileges

Thats it, Restart mysql and good to go with new password..!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!