Change MySQL User Password
April 7, 2025 Β· AI Conversations
—
### β **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.
—
### π οΈ 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?