The solution of forgetting Administrator password in mysql under Linux
What do you do when your mysql administrator password is forgotten? Let's take a look at the following when enabling the mysql service, use the-- skip-grant-tables parameter to skip the permission check to start mysql [root@potato Desktop] # mysqld_safe-- skip-grant-tables 161209 00:01:29 mysqld_safe Logging to'/ data/mysql/mytest_3306/data/error.log'. 161209 00:01:29 mysqld_safe Starting mysqld daemon with databases from / data/mysql/mytest_3306/data can log in directly to mysql (ps: login will have administrator privileges) [root@potato Desktop] # mysql Welcome to the MySQL monitor. Commands end with; or\ g. Your MySQL connection id is 1 Server version: 5.6.34-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Start to change the password, but there is a place to note that if you change the password directly with set, you will report an error. Because you have used-- skip-grant-table, you cannot use root@localhost:mysql.sock 00:02:17 [(none)] > SET PASSWORD FOR 'root'@'localhost' = PASSWORD (' root'). ERROR 1290 (HY000): The MySQL server is running with the-- skip-grant-tables option so it cannot execute this statement, so you can only change the mysql.user permission table directly. Root@localhost:mysql.sock 00:05:52 [(none)] > use mysql Database changed root@localhost:mysql.sock 00:06:10 [mysql] > UPDATE user SET password = password ('root') where user =' root' Query OK, 0 rows affected Rows matched: 1 Changed: 0 Warnings: 0 close the service root@localhost:mysql.sock 00:06:16 [mysql] > quit Bye [root@potato Desktop] # mysqladmin shutdown, then start the mysql service normally, and then log in to [root@potato Desktop] # mysqld_safe [root@potato Desktop] # mysql-uroot-proot Warning: Using a password on the command line interface can be insecure with the changed password. Welcome to the MySQL monitor. Commands end with; or\ g. Your MySQL connection id is 1 Server version: 5.6.34-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
Root@localhost:mysql.sock 00:08:32 [(none)] >
Look, you have successfully logged in. After the ps:mysql administrator forgot his password, do you no longer have to worry about it?