This tutorial guides you through finding and changing your MySQL root password.

We strongly recommend using the database user accounts created through RunCloud instead of the root account for regular tasks. Using the root account carries significant security risks.

This tutorial is for situations where accessing the root password is absolutely necessary.

Step 1: Accessing Your Server via SSH

First, you need to connect to your server using SSH (Secure Shell). You’ll need your server’s IP address or domain name and your SSH username and password (or SSH key). 

To connect using SSH, open your terminal or command prompt and type the following command, replacing your_server_ip with your server’s IP address or domain name, and your_username with your SSH username:

ssh your_username@your_server_ip

You’ll be prompted for your SSH password. Type it in, and press ‘Enter’. You should now be connected to your server. If you need step-by-step instructions for this process, then you can refer to our guide which explains how to use SSH keys with PuTTY on RunCloud

Step 2: Opening the Configuration File with a Text Editor

MySQL’s configuration file holds the root password. It’s usually located in one of these two places:

  • /etc/mysql/conf.d/root.cnf
  • /etc/mysql/my.cnf

In this tutorial, we’ll edit the files using the nano text editor. If nano isn’t installed, you might need to install it using your distribution’s package manager (e.g., apt-get install nano on Debian/Ubuntu). 

To open the configuration file, type one of the following commands in your terminal, replacing the file path with the one that exists on your server (check both locations if one doesn’t exist):

sudo nano /etc/mysql/conf.d/root.cnf
# OR
sudo nano /etc/mysql/my.cnf

To make changes to this system file, you’ll need sudo permission. You’ll also be asked for your server’s root password.

Step 3: Finding and Changing the Root Password

The file will contain various MySQL settings. Look for a section that looks like this:

Replace the value in the password field with your new, strong password. We recommend using a password that includes uppercase and lowercase letters, numbers, and symbols. 

Step 4: Saving the Changes

In nano, press Ctrl + X to exit. You will be prompted to save the changes. Press ‘Y’, and then press ‘Enter’.

Step 5: Restarting the MySQL Service

The changes won’t take effect until you restart the MySQL service. Run the following command to restart the database service:

sudo systemctl restart mysql

After changing the password, you can try connecting to MySQL using the new password either with a tool like MySQL Workbench, or the MySQL command-line client.

Important Security Note: After changing your root password, it’s important to maintain strong security practices. You should avoid using the root account for everyday tasks. Use the dedicated database user accounts provided by RunCloud for your applications.