클라우드 서버 도움말

Reset your root MySQL password - Linux

Difficulty: 1
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

Warning: 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:

Distributions Command
Ubuntu, Debian sudo service mysql stop
Fedora, CentOS 6 sudo service mysqld stop
CentOS 7 sudo systemctl stop mariadb.service
Arch Linux sudo systemctl stop mysqld.service

Reset the root password through safe mode

MySQL safe mode lets you change system settings without using the root password.

  1. Start up safe mode
    sudo mysqld_safe --skip-grant-tables
    You may need to type Enter twice.
  2. Log into MySQL as root:
    mysql -u root
  3. Change to the mysql database, which handles the settings for MySQL itself:
    use mysql;
  4. Update the password for the root user:
    update user set password=PASSWORD("the new password you want to use") where User='root';
  5. Refresh the MySQL user privileges:
    flush privileges;
  6. Exit MySQL:
    exit
    If 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.

  1. Stop MySQL. Use the table in the "Turn off MySQL section" to find the command.
  2. Start MySQL:
    Distributions Command
    Ubuntu, Debian sudo service mysql start
    Fedora, CentOS 6 sudo service mysqld start
    CentOS 7 sudo systemctl start mariadb.service
    Arch Linux sudo systemctl start mysqld.service
  3. Connect to MySQL again with your root user:
    mysql -u root -p
  4. Enter your new password.

That's it! You should now be able to log into your MySQL console with the root password.


이 글이 도움되었나요?
피드백을 보내주셔서 감사합니다. 고객 서비스 담당자에게 문의하시려면 지원 전화 번호 또는 위의 채팅 옵션을 이용하시기 바랍니다.
도와드릴 수 있어 기쁩니다! 더 도와 드릴 것이 있나요?
그것 유감스럽습니다. 혼동이 되었던 사항 또는 솔루션이 고객님의 문제를 해결하지 못했던 원인을 알려주세요.