premise: Client server must be on the same machine to modifyIf there are no other user data in the MySQL library, you can initialize the MySQL library directly. However, if the MySQL library is created many users will not be able to initialize. Only the new password to retrieve the administrator password must stop MySQL service mysqld stop and then manually start MySQL. Editor/etc/init.d/mysqld found a $bindir/mysqld_safe--datadir= "$datadir"--pid-file= "Mysqld_pid_file_path" $other _args >/dev/null 2>&1 & modified to: $bindir/mysqld_safe--skip--grant-tables--skip-networking--datadir= "$datadir"--pid-file= "Mysqld_pid_file_path" $other _args >/ Dev/null 2>&1 &Start the MySQL service again. Then log in and then set the password note here to change the password when you can only change the Mysql.user table inside the Password field of the update user set Password=password (' Set the new password '); where user= ' root '; Then quit MySQL, stop the MySQL service, and re-edit the/etc/init.d/mysqld to change the field back. Restart the MySQL service then Method 2: Use the Mysqld_safe command to add some parameters, login without authorization table first stop the MySQL service and then: Mysqld_safe--skip-grant-tables--user=mysql & Directly open a new shell input MySQL can enterIf you are unable to enter, promptMysqld_safe starting mysqld daemon with databases From/mydata/datamysqld_safe mysqld from PID File/var/run/mysqld/mysqld.pid endedplease view/var/log/mysqld.logI check to see that the log shows this:160412 6:21:04 [ERROR]/usr/local/mysql/bin/mysqld:can ' t create/write to file '/var/run/mysqld/mysqld.pid ' ( Errcode:2)160412 6:21:04 [ERROR] Can ' t start server:can ' t create PID file:no such file or directory160412 06:21:04 mysqld_safe mysqld from PID File/var/run/mysqld/mysqld.pid endedshould be the/var/run/mysqld directory does not exist, the system cannot find the PID file in this directoryWorkaround: Create a new directory and create a PID file under the directoryMkdir/var/run/mysqldCreate a new Mysqld.pid file under the directory and authorize all files below it for MySQL users, MySQL group[email protected] log]# cd/var/run/mysqld[email protected] mysqld]# Touch mysqld.pid[email protected] run]# chown-r mysql.mysql mysqldThen go to modify mysqlku inside User Table update mysql.user Set password = password (' your pwd '); Last refresh permission flush privileges; After you finally start the MySQL service before you use password-free login, the MySQL service has been started, is launched in an unlicensed form, when you update the password, you need to restart the MySQL service, you will/etc/init.d/mysqld stop At this point he will prompt you that the PID file does not exist. Because you did not start with the/etc/init.d/mysqld start, the PID file is not generated so it cannot be restarted. Correct restart mode: Mysqladmin-u root-p shutdown/etc/init.d/mysqld Start
MySQL Root forgot password