Reset MySQL Password

I setup a LAMP server for a developer a while back and he changed the passwords for root and the root mysql user to something besides my defaults. So when he asked me to give him the password for the database, I could not really help him out. Or could I?

Stop the mysql services:
/etc/init.d/mysql stop

Start mysql without the passwords:
mysqld_safe --skip-grant-tables &

Connect to the safe mysql:
mysql -u root

Set a new root password:
use mysql;
update user set password=PASSWORD("your_New_Password_here") where User='root';
flush privileges;
quit

Stop the safe mysql database:
/etc/init.d/mysql stop

Start mysql and test:
/etc/init.d/mysql start
mysql -u root -pYOURNEWPASSWORDHERE

*note – there is no space between -p and your password.

AND, in case you’re just wanting to change the password of a known user:
mysqladmin -u root -pOLDPASSWORD password NEWPASSWORD

Leave a Reply

Your email address will not be published. Required fields are marked *