How to recover your MySQL Password!!

How to recover your MySQL Password!!

Table of contents

No heading

No headings in the article.

Are you having trouble resetting your MySQL password? Look no further! Here's a step-by-step guide for resetting your password on both Mac OS X and Ubuntu.

Step 1: Stop MySQL

sudo systemctl stop mysql

Step 2: Start MySQL in safe mode

sudo mysqld_safe --skip-grant-tables --skip-networking &

The above command helps to run mysql in the backend in safe mode.

Step 3: Log in without a password

now run:-

  mysql -u root

If there is any error like this:-

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

Create a directory using the below command:-

sudo mkdir /var/run/mysqld

Give appropriate permission to the directory

sudo chown mysql: /var/run/mysqld

Now try again step 2 & step 3

Step 4: Reload the grant tables and update the privileges

FLUSH PRIVILEGES;

Step 5: Update your password

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

The command is used to change the password for the user "root" on the "localhost".

Step 6: Stop mysql process running in the background

sudo killall mysqld

Step 7: Start mysql as a service

sudo systemctl start mysql

Now you can access MySQL with the new password.

Resetting a password for a MySQL user on Ubuntu can be done using the steps outlined in this article. The process involves stopping MySQL, starting it in safe mode, logging in without a password, updating the password in the database, and starting MySQL again. By following these steps, you can successfully reset the password for a user in MySQL. It's always a good idea to keep your passwords secure and updated to maintain the security of your database. Don't hesitate to seek additional resources or support if you run into any issues while resetting your password. Happy coding!

Did you find this article valuable?

Support shamnad sherief by becoming a sponsor. Any amount is appreciated!