GitopsCentral

How to reset MySQL Password

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

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

Step-1: Restart MySQL

sudo /etc/init.d/mysql stop

sudo /etc/init.d/mysqld stop

Step-2: 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 beolow, when you try to start mysql, use the resolution show in below steps,

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

Resolution

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

© 2016–2025 GitOpsCentral | All Rights Reserved.