Questions And Answers

More Tutorials

MYSQL Change Password

Change MySQL root password in Linux

To change MySQL's root user password:

Step 1:

Stop the MySQL server.

.in Ubuntu or Debian:
sudo /etc/init.d/mysql stop

.in CentOS, Fedora or Red Hat Enterprise Linux:
sudo /etc/init.d/mysqld stop

Step 2:

Start the MySQL server without the privilege system.

sudo mysqld_safe --skip-grant-tables &

or, if mysqld_safe is unavailable,

sudo mysqld --skip-grant-tables &

Step 3:

Connect to the MySQL server.

mysql -u root

Step 4:

Set a new password for root user.

Version > 5.7
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Version ≤ 5.7
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');


The ALTER USER syntax was introduced in MySQL 5.7.6.

Step 5:

Restart the MySQL server.
.in Ubuntu or Debian:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

.in CentOS, Fedora or Red Hat Enterprise Linux:
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start


In this page (written and validated by ) you learned about MYSQL Change Password . What's Next? If you are interested in completing MYSQL tutorial, your next topic will be learning about: MYSQL Recover and reset the default root password for MySQL 5Point7 PLUS.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.