This article analyzes several methods for retrieving the root password of mysql. We mainly introduce how to retrieve the root password of mysql using multiple methods. Let's take a look at the tutorial below.
This article analyzes several methods for retrieving the root password of mysql. We mainly introduce how to retrieve the root password of mysql using multiple methods. Let's take a look at the tutorial below.
In windows:
Open the command line window and stop the service:
The Code is as follows: |
|
Net stop mysql
|
Start mysql, usually to the installation path of mysql, find the mysqld-nt.exe (or mysqld.exe)
Run: mysqld-nt (or mysqld.exe) -- skip-grant-tables. The current window will stop.
In addition, open a command line window and execute mysql. If the command is not displayed, first enter the BIN directory of the MYSQL installation location and then run mysql.
The Code is as follows: |
|
> Use mysql > Update user set password = password ("new_password") where user = "root "; > Flush privileges; > Exit
|
Use Ctrl + Alt + Del to find the mysqld-nt process and kill it. After restarting the mysql-nt service, you can log on with the new password.
In linux:
If MySQL is running, killall-TERM mysqld is first killed.
Start MySQL: bin/safe_mysqld -- skip-grant-tables &
You can access MySQL without a password.
Then
The Code is as follows: |
|
> Use mysql > Update user set password = password ("new_pass") where user = "root "; > Flush privileges;
|
Kill MySQL again and start it in normal mode
Replace with the MYSQL database of the same version: (make sure to back up the database first)
1. reinstall the same version of MySQL on another computer.
2. Delete all contents of datamysql In the MySQL installation directory on the computer with the password forgotten (stop the MySQL service first)
3. Copy all the contents of datamysql In the MySQL installation directory on the newly installed computer to the directory you just deleted.
4. Start the MySQL service.