Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the problem of MySQL forgetting password

Shulou Source: shulou.com Published: 2022-05-31 19:55:53 09月22日 Update

This article will explain in detail how to solve the problem of MySQL forgetting your password, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

1. Modify MySQL configuration file

First of all, we need to open the configuration file for MySQL. For Windows systems, the configuration file for MySQL is my.ini, which is in the default installation directory for MySQL; for MacOS systems, the configuration file name is my.cnf and its path is / etc/my.cnf.

Taking MacOS as an example, we need to add "skip-grant-tables" after [mysqld] in the configuration file, which means setting to skip permission verification, as shown in the following figure:

MacOS can edit the configuration file directly using the "sudo vim / etc/my.cnf" command.

Matters needing attention

If you cannot find the configuration file for MySQL in MacOS, you can create a my.cnf directly under the / etc directory and add the following:

[client] default-character-set=utf8 [mysqld] bind-address = 127.0.0.1 character-set-server=utf8 skip-grant-tables

Of course, if there are other configuration items, you can also modify them yourself.

two。 Restart MySQL

After modifying the configuration file, we need to restart the MySQL service for the configuration to take effect.

If it is a Windows system, we can shut down and then start MySQL by executing the command as follows:

Net stop mysql net start mysql

If it is a Linux system, you can restart it directly using the command:

Service mysql restart

If it is a Mac system, you can restart it through the interface, as shown below:

3. Set a new password

After restarting the service, we can use the command line tool to set the new password for MySQL. First, we enter the "mysql-u root-p" command to connect to the MySQL server. When the password box appears, you can log in by pressing enter directly, as shown below:

Next, we use the following command to set the new password:

Update user set password=password ('new password') where user='root'; flush privileges; quit

Matters needing attention

If an ERROR 1290 (HY000): The MySQL server is running with the-- skip-grant-tables option so it cannot execute this statement error occurs while performing this step. You need to execute the flush privileges command first, and then execute other commands.

About MySQL forgot password how to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Configuration commands files systems passwords content new secrets services items articles more notes directories knowledge articles input yes next you can use the tool Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Docker Shulou Tech Info macOS