GitopsCentral

Reset MySQL Password

Filed under: Misc — shaik zillani @ 7:28 am

If you have lost your MySQL password and are unable to reset it. Follow this blog post to know how to reset the MySQL password

Restart MySQL

sudo /etc/init.d/mysql stop 
sudo /etc/init.d/mysqld stop

MySQL safe mode

Enter in safe mode and you can access the mysql without using any credentials, after that you can set the password using the query below,

sudo mysqld_safe --skip-grant-tables 
mysql -uroot use mysql; 
update user set authentication_string=PASSWORD("mynewpassword") where User='root'; 
flush privileges; 
quit

Restart MySQL (Ubuntu)

sudo /etc/init.d/mysql stop 
sudo /etc/init.d/mysql start

Restart MySQL (CentOS)

sudo /etc/init.d/mysqld stop 
sudo /etc/init.d/mysqld start

Error while restarting MySQL

You might see the error below when you try to start MySQL. Use the resolution shown in the steps below,

mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

Fix

mkdir -p /var/run/mysqld 
chown mysql:mysql /var/run/mysqld 
mysqld_safe --skip-grant-tables

 

© 2016–2025 GitOpsCentral | All Rights Reserved.