03 March 2011

[Technote] MySQL tips for Linux Ubuntu

I forgot my MySQL server root user password and wondered how I can reset or retrieve my old password in any possible ways. After all, if I couldn't figure out the password or how to reset it, I simply cannot use MySQL server. So here is what I found out about how:

First, to do some little troubleshooting, you might need to make sure your mysql server is running properly:

sudo netstat -tap | grep mysql

And you should see the following message on your terminal:

tcp  0  0  localhost:mysql     *:*     LISTEN      2556/mysqld

If the server is not running properly, you can type this:

sudo /etc/init.d/mysql restart

After that, you can also do some configurations by editing /etc/mysql/my.cnf file. Don't forget to restart your mysql server again after reconfiguration. 

Here comes the most important part - If you would like to change the MySQL root password, in a terminal enter:

sudo dpkg-reconfigure mysql-server-5.1

The mysql daemon will be stopped, and you will be prompted to enter a new password. And you are done. Log in your mysql server next time by entering:

$ mysql -u root -p

$ mysql -uroot -ppassword

No comments: