Reset MySQL root password

Haven’t posted much lately so I figured I’d post some snippets of useful commands for general system administration.  One of the most frustrating things for me is forgetting my root MySQL password >_<  Here’s how to reset the root MySQL password from command line in linux :

First, stop mysqld using the following command:

   /etc/init.d/mysqld stop

OR (depending on your system)

   service mysqld stop

Then, start mysqld again, but like this…

   mysqld_safe –skip-grant-tables

Then login to mysql as root, it won’t ask for a password:

   mysql –user=root mysql

Once your at the mysql prompt, enter the following commands:

   update user set Password=PASSWORD(‘new-password‘) where user=’root’;

   flush privileges;

Then, just stop mysqld again and restart it like normal.  Your new password will be new-password !

🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: