Method 1:
Root User Login System
/Usr/local/mysql/bin/mysqladmin-u root-p password New password
Enter password old password
Method 2:
Log on to the mysql database as a root user.
Mysql> update mysql. user set password = password ("new password") where User = "root ";
Mysql> flush privileges;
Mysql> quit;
What should I do if I forget the root password of mysql?
If MySQL is running, first stop the mysql process: killall mysqld
Start MySQL (abnormal startup):/usr/local/mysql/bin/mysqld_safe-skip-grant-tables &
In this way, you do not need a password to enter MySQL:/usr/local/mysql/bin/mysql-u root-p (you can press enter directly when entering the password)
Mysql> update user mysql. set password = password ("new password") where user = "root ";
Mysql> flush privileges;
Mysql> quit;
Terminate the process again: killall mysqld
Start MySQL in Normal Mode:/usr/local/mysql/bin/mysqld_safe-user = mysql &
Note:
In the update statement, the password = password ("new password") is only used to replace the three words with the password we want to set during the operation. Others are written as they are, the reason for my previous failure was that the parentheses and the previous password were omitted. their role is to store passwords in the database in encrypted form.