21

I have been following these instructions for resetting root password for local installation of MySQL 5.6 on Windows 7 laptop.

I stopped the service, created init-file, and ran the following command (as Administrator):

"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" --init-file=C:\\MySQL-misc\\mysql-init.txt

I got the following warning:

2014-02-08 15:44:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

Since it's a warning I'm not sure whether I need to fix anything and then redo the process again.

Currently the command window is still on and does not accept any input. Should I force-close it or is there anything I can do to complete the process gracefully?

UPDATE

I killed the Command window and tried to restart the service. Got an error.

Restarted Windows and the service automatically started. The new root password seems to work. I was successfully able to use various functions of Workbench that require the password.

So, the warning was indeed just a warning.

5
  • @Mr.Radica - I posted it as an UPDATE. I think it might help someone else, so I didn't delete it.
    – PM 77-1
    Feb 9, 2014 at 0:12
  • Good job. You could still place it below and then accept it. You did solve your initial problem. ;-) Feb 9, 2014 at 0:15
  • I tried almost an hour, followed the instructions on MySQL manual with no success, flushing priviledges etc.. After restarting the computer it worked.
    – endo64
    Aug 31, 2015 at 14:29
  • Thanks! For mysql 5.7, you need to use authentication_string Sep 4, 2018 at 17:34
  • youtu.be/gFo5DV_pSg8 - This video helped me in changing password in one of my production servers.
    – Prem
    Dec 31, 2018 at 19:25

9 Answers 9

63

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
8
  • downvoted because you don't actually say where or how to connect to run the update statement. be complete in your answer. Nov 12, 2015 at 0:11
  • 1
    you forgot FLUSH PRIVILEGES in the 1st (nonMac) instructions? other than that, this worked great, better than the instructions on the MySQL manual
    – knocte
    Nov 7, 2016 at 9:16
  • 3
    Should be noted that there is no 'password' column, at least not in MySql 5.7. Use 'authentication_string', as in @SatishakumarAwati's answer.
    – AJ.
    Mar 21, 2017 at 17:06
  • ERROR 1054 (42S22): Unknown column 'password' in 'field list'
    – Csaba Toth
    Jul 21, 2017 at 18:35
  • 1
    @CsabaToth Try authentication_string
    – Timeless
    Jul 22, 2017 at 1:58
6
  • 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!!

0
4

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).

1
  • thanks alot.... strange ... for me other answers not worked but this answer worked like steph curry 3 points ;) May 28, 2019 at 22:50
2

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.

1

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..!!

1

If you are getting this error: mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. when attempting to reset your root password. You might try:

sudo service mysql stop
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables & 
mysql -uroot
update mysql.user set authentication_string=password('your_password') where user='root';
flush privileges;
quit
sudo killall mysql
sudo service mysql start
mysql -u root -pyour_password

Tested in MySQL 5.7 running in Ubuntu 18.04

0

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.
0

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';
1
  • Where do you run this statement? in cmd?
    – wolfblitza
    Jun 2, 2020 at 23:46
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.