Method 1: log on to the system as the root user/usr/local/mysql/bin/mysqladmin-u root-p password. New password: enter password. Old password
Method 2: log on to the mysql database as the root user and 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 to start MySQL (abnormal startup ): /usr/local/mysql/bin/mysqld_safe-skip-grant-tables & in this way, you can enter MySQL without a password: /usr/local/mysql/bin/mysql-u root-p (press Enter when the password is required) mysql> update user mysql. set password = password ("new password") where user = "root"; mysql> flush privileges; mysql> quit; restart the process: 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. 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.