Mysql Change Root Password

Mysql Change Root Password

May 29, 2020 / Nirav Shah

MySQL is a database management system operated under the Open Source software model. It has become a very popular software package for web application software. Like many web services, MySQL has an administrator-level or root password. The root password allows a user to perform all top-level functions in the database.


Mysql Change Root Password

Steps to reset a MySQL root password

Talk to AWS Certified Consultant

Patient Management Portal

Why you need Spa and Salon management software?
Let Us Talk About Your AWS Development Requirements

WordPress Table of Contents by Topic

If you’ve never set a root password on your MySQL database, you should be able to connect to it. However, this is not a good idea as it means anyone can access your database.

If your database already has a root password, but you lost track of it, this guide will help you reset a Mysql Root password on Linux

Steps to reset a MySQL root password

Use the following steps to reset a MySQL root password by using the command line interface.

  • Step 1: Stop the MySQL service
$ sudo /etc/init.d/mysql stop


  • Step 2: Run the following command. The ampersand (&) at the end of the command is required.
$ sudo mysqld_safe --skip-grant-tables &


  • Step 3: Step 3 ( Optional ) In some cases, you’ve to create the /var/run/mysqld first:
$ sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld


  • Step 4: Connect to MySQL
  • Run the following command:
$ mysql -uroot


  • Step 5: Set a new MySQL root password
  • Run the following command:
  • Change the database to mysql
mysql> use mysql;


  • Replace “mynewpassword”
    • mysql> update user set authentication_string=PASSWORD(“mynewpassword”) where User=’root’;


    • mysql> flush privileges;


    • mysql> exit
  • Step 6: Stop and start the MySQL service
  • Stop the mysql service
$ sudo /etc/init.d/mysql stop


  • Start the mysql service
$ sudo /etc/init.d/mysql start


  • Step 7: Log in to the database
  • Test the new password by logging in to the database.
$ mysql -u root -p


  • Enter your new password when prompted.


Also read: How Enable Username & Password Authentication for Linux EC2


Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project