PDA

View Full Version : How to reset MySQL password via Linux command line



Fli
06-23-2013, 05:28 PM
You will learn how to change and reset mysql password in Linux

Your mysql password can be: blank (empty, just hit Enter button) it can be also your default ssh login password, root, admin, test

if MySQL password is unknown, you can reset it easilly. Before reset, make sure if you are using any hosting control panel that you know how to change mysql root password in this control panel before doing reset. For resetting mysql root password, follow these steps:

How to reset

Stop mysql + start mysql in safe mode + Login to mysql without password


/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables

Then it will probably hang on message "mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql" (http://internetlifeforum.com/mysql-apache-php/2811-hanged-mysqld_safe-starting-mysqld-daemon-databases-var-lib-mysql/). So start new SSH session while keeping old one open.

In new SSH session execute:

mysql --user=root mysql
update user set Password=PASSWORD('YourNewMysqlPassword') where user='root'; flush privileges; exit;/etc/init.d/mysqld start

Source: http://instantcpanelhosting.com/knowledgebase/2/MySQL-password-how-to-reset-it.html

If this dont works, you can also create a php file as a root via command line (vi reset.php) and put this code in it: https://github.com/lxcenter/hypervm/blob/master/hypervm-install/reset-mysql-root-password.phps ; after that, run by command: php reset.php)

How to change password


mysqladmin -u root -p'oldpassword' password newpassword

then enter your present password and hit Enter key

Fli
11-11-2013, 11:43 PM
If above process to reser mysql root password did not worked, my client adviced also this one and used these commands:


mysqld_safe --skip-grant-tables &
mysql -u root
use mysql;
update user set password=PASSWORD(“PASSWORD”) where User=’root’; flush privileges;

this just change the users password, but I couldnt login to 'root'@'localhost' so with this I could succesfully remove the password:


mysqld_safe --skip-grant-tables &
mysql -u root
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password';
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');

It changes root@localhost pass, now i dont have problem

--------------

Do you have any experience yourself? Or another ways on how to reset password?

---

To change password, not reset it, one do: mysqladmin -u root -p'oldpassword' password newpass