Home >Database >Mysql Tutorial >How Can I Reset My MySQL Root Password in Ubuntu?

How Can I Reset My MySQL Root Password in Ubuntu?

DDD
DDDOriginal
2024-12-16 19:12:17329browse

How Can I Reset My MySQL Root Password in Ubuntu?

Resetting or Changing the MySQL Root Password

If you're facing difficulties changing the MySQL root password and username in Ubuntu server, consider the following steps:

  1. Stop the MySQL Service:

    sudo /etc/init.d/mysql stop
  2. Start the MySQL Configuration:

    sudo mysqld --skip-grant-tables &
  3. Connect to MySQL as Root:

    mysql -u root mysql
  4. For MySQL Versions Below 8.0:

    • Update the password:

      UPDATE mysql.user SET Password = PASSWORD('YOURNEWPASSWORD') WHERE User = 'root';
    • Flush privileges:

      FLUSH PRIVILEGES;
  5. For MySQL Versions 8.0 and Above:

    • Flush privileges:

      FLUSH PRIVILEGES;
    • Alter root user:

      ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
    • Flush privileges again:

      FLUSH PRIVILEGES;
  6. Cleanup:

    • Kill the temporary MySQL process:

      sudo killall -9 mysqld
    • Start the normal daemon:

      sudo service mysql start

Remember, this method is not considered the most secure, but it should get the job done. PhpMyAdmin will be updated automatically if it's configured to connect to the MySQL server using the updated credentials.

The above is the detailed content of How Can I Reset My MySQL Root Password in Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn