Blog moved to

Friday, August 17, 2007

MySQL db Password ?

Note: There is nothing new in the following post. Just some redundant info that can be found on web.

I'm from a project which calls itself a research lab. I've never done a serious research till I came out of the project to help a teammate who was doing some other project.

When I was in lab, I use to suggest my teamies to use MySQL rather than heavier databases from MS or Oracle. MySQL is free, lighter and PHP's best friend. We have installed MySQL in almost every desktop and every server in our control. In most of our Projects, we saved usernames and passwords in the MySQL database. What about MySQL's password ?

I remember the cases where my teamies forgot their password and ended up in reinstalling MySQL. Well, that's not at the solution for the problem. Very simple solution is to skip authorization checks and starting MySQL and resetting the password. Login as Administrator or root into the machine and then

  1. If MySQL is running, stop the server
    • Command in Linux : $ killall -9 mysqld
    • Command in Windows : C:\net stop mysql
  2. Start the MySQL server using the following command
    • Linux : /path/to/mysql/bin/safe_mysqld -- skip-grant-tables &
    • Windows : C:\path\to\mysql\bin> mysqld-nt -- skip-grant-tables
  3. Now, you don't need a password to login to MySQL as root
  4. mysql -u root
  5. Mysql> use mysql;
  6. Mysql> update user set password = password ( "newPassword") where user = "root";
  7. Mysql> flush privileges;
  8. Mysql> exit
  9. Restart MySQL server using mysqladmin command
    • mysqladmin -u root shutdown -p
  10. Start MySQL normally

Out of "What the hell is my password ?" to "Hope, I wont forget my new password"

8 responses:

Go Karts! said...

umm..can this command be used remotely as well for example in scripting attacks?

Go Karts! said...

Never mind.. i guess i can google and find out..

K said...

Nopes. You cant use this command "in an attack". But you can certainly use the command if you've shell access to the server as "root" (allowing root to login remotely is usually a very bad practice)

K said...

BTW Karts, Are you from Hillsboro, Oregon ?

ravigurbaxani said...

I have re installed MySQL 4 times because of the same problem. Good article dude

Go Karts! said...
This comment has been removed by the author.
Go Karts! said...

did a guy from * tell u that?

K said...

Do you think I need someone to tell me that ? ;)

Btw, comcast told me and Yes, I'm on that stupid social networking site. Will be on That Guy From star's friend list with name of a Tea brand or one of the wonders.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.

I'm not a lawyer to tell this in a perfect framed sentence. Frame it by yourself if you are so concerned.
Dont think about the content of this blog. Every byte is owned by its rightful owner.
Rest © 2006-2007 Karteek