App overview screenshotSQL and Database Guides
Try our free SQL Client
Connecting to MySQL
Connecting to Drivers
Installing MySQL
Setting up MySQL
MySQL   >   
Setting up MySQL   >   
Reset MySQL 8 Password on Linux

Reset the Password for MySQL 8 on Linux


We may need to change our MySQL passwords for a number of reasons. You might have lost or forgotten the passwords, or have experienced a security concern that prompts you to change it. In either case, this article includes step-by-step instructions on how to reset your MySQL password on a Linux system.


In order to complete this tutorial, you must have the following:

  • You should have MySQL installed on your system
  • You should have a text editor, such as VS Code
  • You should have access to the command-line interface (terminal)

How to reset your MySQL8 password on Linux

Step 1: Stop the MySQL server

To begin, we must first stop the MySQL service. Do this by running the following commands in the terminal:

# systemctl stop mysqld.service     
# /etc/init.d/mysqld stop

We now have two options on how to proceed.

Step 2, Option 1: use –init-file

To do this, open your code editor and generate a file that contains some SQL code, which will be used to reset the password. Create a new file and add the following code inside it:

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

Replace the root username with the username for which you wish to reset the password, as well as the new password string with the desired password. Save the file in /home/user/init-file.txt. Then run the following command:

# mysqld --user=mysql --init-file=/home/user/init-file.txt --console

Running the above command will start the MySQL service and execute the init-file that we created. This will change the user's (root's) password to the new password we specified in the file.

reset mysql password linux approach 1

Note: If you use this approach, you should skip the next step and log in directly with the new MySQL password.

Step 2, Option 2: use –skip-grant-tables

The second method is to start the MySQL service with the --skip-grant-tables option. If the --skip-grant-tables command is used to start the server, the option —skip-networking is enabled by default, prohibiting remote connections.

You can use this command to reset your password. Run the command code block below on the terminal.

# mysqld --skip-grant-tables --user=mysql &
# mysql

To update the password, type the following command into the command prompt. Make sure "new password" is replaced with the exact password you want to use.

# ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

The above command will successfully reset the MySQL password.

reset mysql password linux approach 2

Step 3: Log in with the new password

Now that you've successfully updated the MySQL password, you'll need to restart the MySQL service with the following command:

# systemctl stop mysqld.service       
# systemctl restart mysqld.service     
# /etc/init.d/mysqld stop  

# /etc/init.d/mysqld restart  

Run the following code in the terminal to login into MySQL using the new password:

# mysql -u root -p

Then enter the new password to log in to the MySQL service. You can then interact with your data using a SQL client like Arctype. In order to update the new MySQL password with your Arctype workspace, you can check the Arctype documentation for more details.

password reset success


We learned how to change MySQL passwords on Linux by following these step-by-step instructions. If you follow those steps, you should be able to change your MySQL password easily. If you’re interested in learning more about MySQL, you can visit the Arctype documentation and Arctype blog, which contain additional details.

You can also join the Arctype Discord to get help and inspiration from hundreds of SQL experts from around the world.

Get help on databases and SQL. Join our Discord community.