- Help Center
- Server Administration
- UNIX Instructions
How to change MySQL root user password
1. Connect via SSH to the VPS.
2. Connect to MySQL as root user:
mysql –u root –p
3. Press Enter. Enter your current password. Press Enter.
4. Run the command:
SET PASSWORD FOR 'root' @ 'localhost' = PASSWORD ('newpassword');
5. Quit.
You can change the password for other MySQL users. Replace root with the username for which you want to change the password.
How to change MySQL root user password if current password has been lost
1. Connect via SSH to the VPS.
2. Stop the MySQL server. Run the following command, depending on your operating system.
Debian / Ubuntu |
/etc/init.d/mysql stop |
CentOS / Fedora |
/etc/init.d/mysqld stop |
CentOS 7 |
systemctl stop mariadb |
3. Run the command:
mysqld_safe --skip-grant-tables &
4. Connect to the MySQL server as root. No password is required, since the MySQL server is running in safe mode:
mysql -u root
5. Select the MySQL database:
use mysql;
6. Set a new password:
update user set password = PASSWORD ("newpassword") where User = 'root';
7. Reload the privileges:
flush privileges;
8. Disconnect from MySQL:
quit;
9. Stop and start MySQL using the following commands, depending on your operating system:
Debian / Ubuntu |
/etc/init.d/mysql stop /etc/init.d/mysql start |
CentOS / Fedora |
/etc/init.d/mysqld stop /etc/init.d/mysqld start |
CentOS 7 |
systemctl stop mariadb systemctl start mariadb |
10. Test the connection to MySQL with the new password:
mysql -u root -p
If you have any questions, please create a ticket to technical support.