GICT knowledge base
How to recover the mysql root password?
Published
Steps to recover the mysql root password
1.Stop the mysql service
# service mysql stop
(or)
# /etc/rc.d/init.d/mysql stop
2.Start mysql in safe mode by using command mysqld-safe
# mysqld_safe –skip-grant-tables
It will not read the grant tables and allows anybody to enter in to mysql without asking the password.
3.Login to mysql
# mysql -u root
4.Use the mysql database which contains the passwords for all the databases and update the root password with the following command
# use mysql;
# UPDATE mysql.user SET Password=PASSWORD(‘password’) WHERE User=’root’;
5. Exit from mysql and stop the mysql service
mysql> exit
# service mysql stop
6. Remove the entry “skip-grant-tables” in the mysql startup script /etc/rc.d/init.d/mysql
# vi /etc/rc.d/init.d/mysql
Old entry: $bindir/mysqld_safe –skip-grant-tables –datadir=$datadir –pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
New entry: $bindir/mysqld_safe –datadir=$datadir –pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
7. Start mysql service
# service mysql start
Now it will ask the password when some one tries to login to mysql
8. Login to the mysql root accout with the new password
# mysql -u root -p newpassword
Related guides
Check MariaDB Versions and Compatibility on Shared Hosting
Check your actual MariaDB/MySQL server version, maintenance coverage and application requirements before requesting a shared-hosting upgrade or move.
MySQLHow to Monitor MySQL Database Server Performance
Learn how to monitor MySQL performance with 4 essential Linux command-line tools.
MySQLHow to secure MySQL connections with SSL on Ubuntu
MySQL allows remote connections and we must protect data transfer happeneing between servers with SSL. Follow this tutorial to learn how.
MySQLHow to set up High Availability WordPress with HyperDB
HyperDB is a drop-in plugin that allows you to set up High Availability WordPress site that can work with multiple database servers at once.
