# Resetting the MySQL root password

> Reset a forgotten MySQL root password on your VPS over SSH by restarting MySQL without permission checks and setting a new password.

Source: https://helpcenter.ruachost.com/vps/guides/resetting-the-mysql-root-password/

This guide explains how to **reset the MySQL root password**, for example, if you have forgotten it.

**Note:** You must have **root access** on the server to perform these steps.

## **Steps to Reset the MySQL Root Password**

1. **Log in via SSH** to your server.

**Note:** Run the following commands as the **root user**. You can either log in directly as root (not recommended for security reasons) or use `su` / `sudo`.

2. **Stop the MySQL server**:

- ### AlmaLinux / Fedora

```
service mysqld stop
```

- ### Debian / Ubuntu

```
service mysql stop
```

3. **Restart MySQL with grant tables disabled**:

```
mysqld_safe --skip-grant-tables &
```

**Important:** The `&` runs the command in the background, allowing you to continue typing commands.\
Running MySQL this way is **highly insecure**—only do this briefly to reset the password.

4. **Log into MySQL**:

```
mysql
```

5. **Reset the root password**:

```
UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
```

Replace `'new-password'` with your desired root password.

6. **Apply changes and exit**:

```
FLUSH PRIVILEGES;
exit;
```

7. **Stop MySQL safely**:

```
mysqladmin -u root -p shutdown
```

- Enter the new root password when prompted.

8. **Start MySQL normally**:

- ### AlmaLinux / Fedora

```
service mysqld start
```

- ### Debian / Ubuntu

```
service mysql start
```

Your MySQL root password is now successfully reset.
