Did you forget the root password for your MySQL Server?

Or maybe you provisioned your RunCloud server via the auto-install method and never had the need to use your password in the first place?

Whatever may be the case, if you want to reset your MySQL password then you’ve come to the right place!

In this guide, we’ll walk you through how to set, change, and recover your MySQL root password on an Ubuntu server via MySQL command line.

If you have no prior experience managing MySQL, don’t worry – with RunCloud, it is as easy as ABC.

How to Reset Your MySQL Root Password in Linux

Step 1: Log in to the Server with SSH

We have already written in-depth documentation on connecting to your RunCloud account via SSH, but if you’re not using RunCloud, you can use the following SSH command to log in to your server:

ssh user@server_ip_address

In the above command, replace the user with the username of your Linux account, and server_ip_address with your server’s IP address.

Keep in mind that the Linux account must have superuser permissions to execute the commands given in the next step.

Step 2: STOP MySQL Server

After logging in to your server, you need to stop the MySQL service. You can use the following command to do this:

Note: If you have any websites or other services that are using this database, then they will not be able to connect to your database while you carry out this action, so it is best to do this outside of business hours.

sudo systemctl stop mysql
logging into root user via command line

Step 3: Restart MySQL Server

After stopping the server, you can now restart it in the safe mode. This will allow us to execute SQL commands without needing to enter the password.

Since the command --skip-grant-tables enables anyone to connect without a password, it is considered highly insecure, which is why all commands that follow must be done within a brief period. The ampersand (&) at the end is required as it ensures that the command is being run parallel with the commands that follow afterwards.

To start MySQL without permission checking, execute the following command:

sudo mysqld_safe --skip-grant-tables &
MySQL root password

Step 4: Log in to MySQL

Once your server is up and running, you can log in to MySQL as the root user without the need for any password by executing the following command:

mysql -u root

Step 5: Change MySQL Password with Command Line

Once you’re logged in to the MySQL server, you can do anything you like – such as changing the password for users, granting permissions, deleting database, etc.

To change the root password, execute the following command:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'RunCloud_password';

In the above command, replace the RunCloud_password with your new password.

Alternatively, you can also use the following command to change the password:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('RunCloud_password');

Step 6: Stop & Restart MySQL Server

Finally, you need to stop the MySQL service and restart it in normal mode. To do this, first exit from the MySQL CLI by using the exit; command, and then restart the service using the following commands:

sudo systemctl stop mysql
sudo systemctl start mysql

That’s it! Once your server is up and running, you can start using it normally. To log in to your server via the new password, use the following command:

mysql -u root -p

The above command will prompt you to enter a password. To complete the login process, type your password and press Enter. Keep in mind that the password will not be displayed on screen for security reasons.

Frequently Asked Questions

How do I find my MySQL root password?

You cannot directly find the MySQL root password due to security reasons. However, you can reset it. To recover the password, you need to stop the MySQL server process, start the MySQL server with the --skip-grant-tables and --skip-networking options, and then connect to the MySQL server as the root user.

What is the password for the root user in MySQL Workbench?

The password for the root user in MySQL Workbench is the one you set during the installation of MySQL. If you haven’t set any password, you might be able to log in directly.

How to change SQL password using CMD?

You can change the SQL password using the command line by using the ALTER USER statement.

How to reset MySQL root password in Docker?

To reset the MySQL root password in Docker, you need to first access your MySQL container using the docker exec command and then, follow the steps described in this post to reset your root password.

How to reset the root password in MySQL Mac?

To reset the root password in MySQL on a Mac, you need to stop the MySQL Server first. Then, start the server in safe mode with a privilege bypass. In a new window, connect to the database, set a new password (as explained in this post), and flush the permissions.

Can a MySQL user change their own password?

Yes, a MySQL user can change their own password using the SET PASSWORD or ALTER USER statement.

How to Recover the MySQL Root Password?

Unfortunately, you cannot retrieve the MySQL root password. However, you can reset it by following the steps mentioned in this post.

How to find MySQL root password in RunCloud?

If you install RunCloud via manual installation, then the MySQL root password is displayed on your terminal screen at the end of the RunCloud agent installation on your server.

Wrapping Up

RunCloud is a powerful and easy-to-use platform that helps you manage your websites on any cloud server. With RunCloud, you don’t need to be a Linux expert to set up, secure, and optimize your web applications. You can do everything from a simple and intuitive dashboard, saving you time and hassle.

RunCloud supports various web servers, PHP versions, databases, and frameworks. You can also monitor your server performance, back up your data, and automate your tasks with RunCloud. Whether you are a developer, a freelancer, or a business owner, RunCloud can help you run your websites faster and smoother.

What are you waiting for? Join RunCloud today and enjoy the best web hosting solution for your websites. It’s free for 7 days, no strings attached!