1. Home >
  2. Apps >
  3. Groups >

How to reset SQL root password

Question asked by as_nawin in #Databases on Oct 16, 2009
as_nawin
as_nawin · Oct 16, 2009
Rank D2 - MASTER
Lost your MySQL root password? Resetting MySQL root password is simple. Please follow these steps-

# Login to your MySQL server.
# Locate the mysql.ini file.
-This should be something like C:\MySQL\my.ini or “C:\Program files\MySQL\bin\mysqld-nt.exe” –defaults-file=”C:\Program files\MySQL\Data\my.ini” MySQL
-You can also check this by viewing the Properties of the MySQL service command line under the Services MMC.
# Edit the appropriate *.ini file and add the following line immediately after [mysqld] ;
skip_grant_tables = 1
# Restart the MySQL service. Please note that MySQL is now running unsecured.
# From a command prompt, change to the /bin directory (Ususally C:\MySQL\bin or whereever under MySQL installed location) and enter the following command to login as root:
mysql -u root
# Then input the following command:
update mysql.user SET Password = Password(’newpassword’) WHERE User=’root’;
# Now remove the line you added to my.ini in previous step and restart MySQL.
# Make sure you can login to MySQL using the updated password.
Posted in: #Databases
safwan
safwan · Oct 17, 2009
Rank B2 - LEADER
I think this should come in CS section.
Divisha Madupalli
Divisha Madupalli · Feb 20, 2020
Rank C1 - EXPERT
  • Log in to your account using SSH 
  • Stop the MySQL server using the appropriate command for your Linux distribution:
  • For CentOS and Fedora, type:
  • service mysqld stop
  • Restart the MySQL server with the —skip-grant-tables option. To do this, type the following command:
  • mysqld_safe --skip-grant-tables &
  • Log into MySQL using the following command:
  • mysql
  • At the mysql> prompt, reset the password. To do this, type the following command, replacing NEW-PASSWORD with the new root password:
  • UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';
    1. At the mysql> prompt, type the following commands:

      FLUSH PRIVILEGES; exit;

    2. Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:

      mysqladmin -u root -p shutdown


You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up