Coding, Web Design Process

Changing MySQL Database Password via SSH

Securing your MySQL database is essential to protect sensitive data and prevent unauthorized access. One crucial aspect of database security is regularly changing the database password.

In this article, we will guide you through the process of changing the MySQL database password via SSH (Secure Shell), a secure remote access protocol widely used for server administration.

Step 1: Accessing the Server via SSH: To begin, you will need SSH access to the server hosting your MySQL database. Use a terminal or SSH client of your choice and connect to the server using the appropriate credentials provided by your hosting provider or system administrator.

Step 2: Logging into MySQL: Once connected to the server, you need to log in to the MySQL database using the command-line interface. Enter the following command and press Enter:

mysql -u root -p

You will be prompted to enter the password for the MySQL root user. Provide the current password and press Enter.

Step 3: Selecting the Database: After successfully logging in to the MySQL database, select the specific database for which you want to change the password. Execute the following command, replacing <database_name> with the name of your database:

USE <database_name>;

Step 4: Changing the Password: With the desired database selected, you can proceed to change the password for a specific user. Execute the following command, replacing <username> and <new_password> with the appropriate values:

ALTER USER '<username>'@'localhost' IDENTIFIED BY '<new_password>';

Note: Replace localhost with the appropriate hostname or IP address if you wish to change the password for a remote user.

Step 5: Applying the Changes: After executing the previous command, the password for the specified user will be updated. However, the changes will not take effect until you flush the privileges. Enter the following command to apply the changes:


Step 6: Verifying the Password Change: To ensure the password change was successful, exit the MySQL prompt by typing exit and pressing Enter. You will return to the command line. Now, you can log in to MySQL again using the new password:

mysql -u <username> -p

Enter the new password when prompted. If the login is successful, congratulations! You have successfully changed the MySQL database password.

Changing your MySQL database password periodically is a vital security practice that helps safeguard your data. By following the step-by-step guide outlined in this article, you can confidently change your MySQL database password via SSH. Remember to keep your passwords strong, confidential, and unique for each database user to maximize security.

AW Bali Digital

© 2024 by PT BIKIN INOVASI TEKNOLOGI, All Rights Reserved.