Change MySQL User Password

User
hetzner cloud I have ssh access now want to change password of mysql user
Assistant
Great! If you have SSH access to your Hetzner Cloud server and want to change the password of a MySQL user, you can follow these steps:

### βœ… **Step-by-step: Change MySQL User Password via SSH**

1. **SSH into the server** (if not already connected):

ssh your_user@your_server_ip

2. **Log into MySQL as root** (or with a privileged user):

mysql -u root -p

> You’ll be prompted to enter the MySQL root password.

### πŸ” **Change Password for an Existing MySQL User**

Once inside the MySQL shell:

ALTER USER 'username'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;

> Replace:
> – `username` with the actual MySQL username
> – `'localhost'` with the correct host if different (e.g., `'%'` for any host)
> – `new_password` with your new desired password

### βœ… **Example**

ALTER USER 'salesiq_user'@'localhost' IDENTIFIED BY 'Str0ngNewPass!';
FLUSH PRIVILEGES;

### πŸ’‘ **If you get an error like `ERROR 1396`…**

That usually means the user doesn't exist exactly as defined. Try checking existing users with:

SELECT user, host FROM mysql.user;

This helps you identify the correct `user@host` combo.

### πŸ”„ **Exit MySQL**

EXIT;

If you're managing **replicated databases (master/slave)**, make sure to repeat this password update on both servers to maintain sync.

Let me know if you want to change password for multiple users, create a new user, or assign to a specific database.

User
but i have not root user password
Assistant
No worries! If you **don’t have the MySQL root password** but **have full SSH access**, you can still reset the MySQL root password and then change any user's password.

### πŸ› οΈ Option 1: **Reset MySQL root password (Linux SSH method)**

1. **SSH into your Hetzner server**

ssh your_user@your_server_ip

2. **Stop MySQL service** (based on your OS, most likely Ubuntu):

sudo systemctl stop mysql

3. **Start MySQL in safe mode without password auth**:

sudo mysqld_safe --skip-grant-tables &

Wait a few seconds until it fully starts.

4. **Log into MySQL without password:**

mysql -u root

5. **Reset the root password:**

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongRootPassword!';
FLUSH PRIVILEGES;
EXIT;

6. **Stop the safe mode MySQL process**

sudo killall mysqld

7. **Start normal MySQL service again**

sudo systemctl start mysql

### βœ… Now you can log in as root

mysql -u root -p

Use the new password you just set.

Then you can change any other MySQL user's password:

ALTER USER 'username'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;

Let me know if you're using MariaDB instead, or if it's a managed DB setup β€” steps might vary slightly. Want me to generate the full set of commands tailored for your system?

Leave a Comment

Your email address will not be published. Required fields are marked *