Reset your root MySQL password - Linux
Time: 30 minutes
If you've forgotten the root user's password you created for your MySQL database, you can reset it.
It's important to note that this user and its password are limited to administrator use. This is not the user or password you should use for everyday use.
Turn off MySQL
If you have any sites or application that rely on MySQL to function, these will stop working until you turn MySQL back on.
You must turn the MySQL service off to reset the root password. The command you use to turn MySQL off varies depending on your Linux distribution. Choose the command from the table below for the Linux version you are using:
|Fedora, CentOS 6||
Reset the root password through safe mode
MySQL safe mode lets you change system settings without using the root password.
- Start up safe mode
sudo mysqld_safe --skip-grant-tablesYou may need to type Enter twice.
- Log into MySQL as root:
mysql -u root
- Change to the mysql database, which handles the settings for MySQL itself:
- Update the password for the root user:
update user set password=PASSWORD("the new password you want to use") where User='root';
- Refresh the MySQL user privileges:
- Exit MySQL:
exitIf this doesn't work, you can try force the application to quit by pressing CTRL-C on your keyboard.
Stop and Start MySQL
Now that the password has been reset, you need to stop and start the MySQL service.
- Stop MySQL. Use the table in the "Turn off MySQL section" to find the command.
- Start MySQL:
Distributions Command Ubuntu, Debian
sudo service mysql start
Fedora, CentOS 6
sudo service mysqld start
sudo systemctl start mariadb.service
sudo systemctl start mysqld.service
- Connect to MySQL again with your root user:
mysql -u root -p
- Enter your new password.
That's it! You should now be able to log into your MySQL console with the root password.