I have been following these instructions for resetting root password for local installation of MySQL 5.6
on Windows 7 laptop.
I stopped
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
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.
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
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!!
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
In case if you have Xampp installed.
skip-grant-tables
under [mysqld]
C:\xampp\mysql\bin\mysql
update mysql.user set password=PASSWORD('root') where user='root';