What should I do if I forget the MySQL root Password?
In the daily development or maintenance of MySQL, it is often difficult to avoid some problems or faults, such as lost passwords and table damage. To sum up the commonForget the MySQL root PasswordSolution:
1. log on to the server where the database is located and manually kill the Mysql process
Command:Kill process number
(In linux)
Command:Taskkill process number
(Win)
How can I view the process number?
We all know that the MySQL process number is generally stored in the Mysql data directory, which records the Mysql service process number. The file name is hostname. pid, as shown below, where YEGZT8JOIIU2LKY is the host name.
Run the ps command to view processes in linux. In win, run tasklist to view process numbers,
Open the file and you can see that it only records the process number.
Now, for convenience, I mainly demonstrate how to operate in windows. I am not ready to open the Virtual Machine for testing. If we are not familiar with the taskkill command, we can use taskkill /? To view the command.
2. Use the-skip-grant-tables option to restart the MySQL service.
Linux
Syntax:./bin/mysqld_safe-skip-grant-tables
The-skip-grant-tables option indicates that mysql is started.
(Note that for Mysql installed in win, I use mysqld-skip-grant-tables)
3. Use the root user with an empty password to connect to MySQL and modify the root password.
Modify as follows:
The set password command fails because-skip-grant-tables is used for startup.
Use the update statement to directly update the user table in the mysql database.
4. Update Permissions
5. Log On again
After logging out, you can only use the password to log on to mysql-uroot.
The above is the solution for forgetting the root password, hoping to help you learn.