Ubuntu Linux, ubuntu desktop, Linux operating system, ubuntu guide

Tag: How to Reset the mysql root password

How to Reset the mysql root password in LInux

by on May.31, 2010, under Mysql, RHEL5, Ubuntu, ubuntu 10.04, ubuntu 7.10, ubuntu 8.04, ubuntu 8.10, ubuntu 9.04, Ubuntu 9.10

Mysql installation time, If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:

$ mysqladmin -u root password NEWPASSWORD

However, if you want to change (or update) a root password, then you need to use following command

$ mysqladmin -u root -p'oldpassword' password newpass

For example, If old password is dbase, and set new password to dbase123, enter:

$ mysqladmin -u root -p'dbase' password 'dbase123'
Other then the ways specified here to reset and change the root password for mySQL in the case that the password is forgotten or lost,
1)Stop the mysql demon process using this command

sudo /etc/init.d/mysql stop

2)Start the mysqld demon process using the –skip-grant-tables option with this command

sudo /usr/sbin/mysqld –skip-grant-tables –skip-networking &

3)start the mysql client process using this command

mysql -u root

from the mysql prompt execute this command to reset/update your password

SET PASSWORD FOR root@’localhost’ = PASSWORD(‘password’);

If you have a mysql root account that can connect from everywhere, you should also do:

UPDATE mysql.user SET Password=PASSWORD(‘newpwd’) WHERE User=’root’;

Alternate Method:

USE mysql
UPDATE user SET Password = PASSWORD(‘newpwd’)
WHERE Host = ‘localhost’ AND User = ‘root’;

And if you have a root account that can access from everywhere:

USE mysql
UPDATE user SET Password = PASSWORD(‘newpwd’)
WHERE Host = ‘%’ AND User = ‘root’;

For either method, once have received a message indicating a successful query (one or more rows affected), flush privileges:

FLUSH PRIVILEGES;
exit


Then stop the mysqld process

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
1 Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!