Home >Database >Mysql Tutorial >How to Reset MySQL 8 Root Password After Install using ALTER USER?

How to Reset MySQL 8 Root Password After Install using ALTER USER?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-19 07:02:08387browse

How to Reset MySQL 8 Root Password After Install using ALTER USER?

Resetting MySQL 8 root Password After Install using ALTER USER Statement

You have encountered an issue where resetting the MySQL root password using the traditional method fails. This is because the password needs to be set using the ALTER USER statement instead.

First-Time Password Setup:

If this is your first time setting the root password, execute the following command:

mysql> SET PASSWORD = PASSWORD('your_new_password');
Query OK, 0 rows affected, 1 warning (0.01 sec)

Existing Password Reset:

If you need to reset the password for a non-first-time setup, follow these steps:

  1. Connect to the MySQL server as the root user.
  2. Enter the command:
mysql> UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';

Additional Notes:

  • Ensure that your database is running on port 3306.
  • Provide the correct path to the MySQL binary.
  • Check if the error is caused by your MySQL version.

Reference:
[ALTER USER Syntax](https://dev.mysql.com/doc/refman/5.6/en/alter-user.html)

The above is the detailed content of How to Reset MySQL 8 Root Password After Install using ALTER USER?. 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