Google
 
2007-04
20

Recover MySQL Database root password

Filed under: Tech articles — woojar @ 10:34 am

By default, MySQL Server will be installed with root superuser without any password. You can connect to MySQL server as root without requiring password or by keying in blank password. However, if you have set the password for root and forget or unable to recall the password, then you will need to reset the root password for MySQL.

Login as root to the Unix-like (Unix, Linux or BSD) machine with the MySQL server.

Stop the MySQL server by using either of the following command

#/etc/init.d/mysql stop

Now you need to Start MySQL server without password

# mysqld_safe --skip-grant-tables &

Connect to mysql server using mysql client with the following command

# mysql -u root

Now you should be having mysql prompt

mysql>

Now you need to Setup new MySQL root user password

mysql> use mysql;

mysql> update user set password=PASSWORD(”newrootpassword”) where user=’root’;

mysql> flush privileges;

mysql> quit

Note: Replace newrootpassword with the new root password for MySQL server. Flush Privileges is needed to making the password change effect immediately.

Now you need to Stop mysql with the following command

# /etc/init.d/mysql stop

Test Your New Mysql root password

First you need to start mysql server using the following command

# /etc/init.d/mysql start

# mysql -u root -p

Now it will prompt for root password and enter your new root password


Technorati :

Tags: , ,

Related posts

1 Comment »

  1. Thanks for your info., I successfully reset password for my MySQL dB!

    For my version of dB, version 5.018 with Linux FC5,
    I have to change all command with “mysql” to “mysqld”
    for example :
    “/etc/init.d/mysql start” –> “/etc/init.d/mysqld start”

    Thanks again

    Comment by Patrick Lee (HKG) — 2007-07-31 @ 8:46 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

39 queries. 0.339 seconds. Powered by WordPress
沪-ICP备07003363号 Stat.