Tuesday 17 January 2012

How to Recover a Mysql Root Password


Let's  check how can we recover mysql root password if we lost it

Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
Step # 3: Connect to mysql server as the root user.
Step # 4: Setup new mysql root account password.
Step # 5: Exit and restart the MySQL server.

Here are commands you need to type for each step (login as the root user)

# service mysqld stop 
# mysqld_safe --skip-grant-tables &

[1] 13964
root@localhost ~]# Starting mysqld daemon with databases from /var/lib/mysql  ------------nothing will show just type mysql
mysql ----- typing mysql shows like this
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
Or 
ctrl z then

#mysql
mysql> use mysql;
mysql>update user set password=PASSWORD("password@123#") WHERE user="root"; 
mysql> flush privileges;  
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

# mysql -u root -p  ------ enter the database with new password



No comments:

Post a Comment