modify Linux In the system MySQL Database root password
If you forget MySQL database root User's password , You can modify the configuration file , Skip password on login , Then change the password in the database . The default user of general database is root.
1. Execute the following command , edit MySQL Database my.cnf The configuration file .
notes ：my.cnf The path of the configuration file is based on the actual environment .
2. stay \[mysqld\] Add the following under the field , Then save to exit .
3. Execute the following command , restart MySQL service .
notes ：MySQL The startup script path is based on the actual environment .
4. Execute the following command , Log in to the database .
notes ：MySQL The command path is based on the actual environment .
5. In turn, execute as follows SQL sentence , Update the password .
UPDATE user SET Password = password ('\[$Password\]') WHERE User = 'root';
notes ：\[$Password\] For new password , It is not recommended that the new password be “123456”, This password is too simple , Passwords need to meet password complexity requirements , You need a combination of uppercase and lowercase letters and numbers , The minimum length is 8 position , According to this password policy , Set the password .
perform UPDATE user SET Password = password ('\[$Password\]') WHERE User = 'root'; Report a mistake later ERROR 1054(42S22) Unknown column 'password' in ‘field list’
The reason for the mistake is 5.7 Version on mysql There is no password This field ,password Field changed to authentication_string ,
namely ：UPDATE user SET authentication_string = password ('mimimimi') WHERE User = 'root';
6. Edit again /etc/my.cnf The configuration file , Delete or annotate section 2 Step added skip-grant-tables.
7. Execute the following command , restart MySQL service .
8. Log in to the database with your new password , Confirm normal login .