# Reset user password in MySQL

Let's see how to reset the MySQL user password.

I am using the below commands to reset the MySQL root user password in the Ubuntu 22 LTS.

1. Stop the MySQL by the following commands
    

```bash
sudo systemctl stop mysql
```

```bash
sudo /etc/init.d/mysql stop
```

2. Run the mysqld
    

```bash
sudo mysqld_safe --skip-grant-tables &
```

If you face the error like below,

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

Then run the below commands, to create and folder and update the permission

```bash
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
```

3. Login into the MySQL
    

Use the below command to login, without password

```bash
mysql -u root
```

Change the databse to `mysql`, by usnig the below command

```sql
use mysql;
```

Flush the privileges

```sql
FLUSH PRIVILEGES;
```

Try to alter the password, by using the command

```sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
```

If you face the below error

```bash
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded
```

Then, update the Plugin for authentication

```sql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
```

Exit from mysql

```sql
exit
```

4. Stop the MySQL service
    

```bash
sudo systemctl stop mysql
```

5. Start the service
    

```bash
sudo systemctl start mysql
```

And, try to login into mysql now with new password you set

```bash
mysql -u root -p
```

Hope it will prompt for password, Enter the password

```bash
password:
```
