/ mozey.co / blog

mysql change password

July 1, 2013

🔗 Linux

If you know the current password use this, you will be prompted for the current password.

mysqladmin -u root -p password myNewPassword

If you don’t have the current password follow these steps.

Stop the database service

sudo service mysql stop

Make sure it is not running

ps ax | grep mysql

Start the server using this option (taking note of the pid)

sudo mysqld --skip-grant-tables &

Login as the root user

mysql -u root

And change the root password, for MySQL 5.7.6 and later

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

Or MySQL 5.7.5 and earlier

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

flush privileges;


Stop the database service and restart

sudo kill pid

sudo service mysql start

Login using the new password

mysql -u root -p

🔗 Windows

Resetting the Root Password

Log on to your system as Administrator

Stop the MySQL server if it is running

Create a text file containing the following statement on a single line

set password for 'root'@'localhost' = password('NEW_PASSWORD');

Start the MySQL server with the special –init-file option

cd "C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin"

mysqld.exe --init-file=C:\\mysql-init.txt

Delete C:\mysql-init.txt

Stop the MySQL server and restart it normally