MySQL database root password restoration method 1
1. download the MySQL source code distribution package. we don't need to differentiate the operating system. we need the same thing;
2. rename the mysql folder in the data directory of your mysql database to oldmysql;
3. copy the mysql directory under the data directory in the source code package to the data directory of your mysql;
4. restart mysql. now the mysql authorization relationship is the same as that of the new installation. log on with a blank password and adjust the authorization;
5. open the database oldmysql to check what is going on;
6. if there is a backup, the integrity of the original database in the system will be checked to avoid modification.
Method 2
1. send the kill command to the mysqld server to disable the mysqld server (not kill-9). the files that store the process ID are usually located in the directory of the MYSQL database.
Kill 'cat/mysql-data-directory/hostname. Pi'
You must be the root user of Linux or the same user on the SERVER where you are running;
Killall-TERM mysqld
2. use the '-- skip-grant-tables' parameter to start mysqld;
Shell> mysqld_safe -- skip-grant-tables &
/Bin/safe_mysqld -- skip-grant-tables &
3. use the 'MySQL-h hostname mysql' command to log on to the mysqld server and use the grant command to change the password. You can also do this:
'Mysqladmin-h hostname-u user password' new password''
It can also be used
Use mysql; update user set password = password ('yourpass') where user = 'root'
;
Shell> mysqladmin-u root flush-privileges password "newpassword"
> Use mysql
> Update user set password = password ("new_pass") where user = "root ";
> Flush privileges;
4. load the permission table:
Mysqladmin-h hostname flush-privileges'
Or use SQL commands
'Flush privileges'
Of course, you can restart mysqld here.