One: Problem description
--Login MySQL
[Root@target_pc software]# mysql-u root-p
Enter Password:
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)
II: Solutions
[Root@target_pc software]#/etc/init.d/mysql stop
Shutting down MySQL. [OK]
[root@target_pc software]# mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
[1] 3119
[root@target_pc software]# 140918 23:02:23 mysqld_safe Logging to '/var/lib/mysql/target_pc.err '.
140918 23:02:23 Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql
-It will stay in the interface for a while, feel the need to wait the same, at this point, direct return on the line.
[Root@target_pc software]# mysql-u root-p
Enter Password:
--No need to enter the password, direct return on the line.
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.6.20 MySQL Community Server (GPL)
Copyright (c), 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
mysql> use MySQL;
Reading table information for completion of table and column names
You can turn off the feature to get a quicker startup with-a
Database changed
mysql> Update user set Password=password (' Beijing ') where user= ' root ';
Query OK, 4 rows affected (0.01 sec)
Rows Matched:4 Changed:4 warnings:0
mysql> FLUSH privileges;
Query OK, 0 rows Affected (0.00 sec)
Mysql> quit
Bye
[ROOT@TARGET_PC software]#/etc/init.d/mysql Restart
Shutting down MySQL. 140918 23:07:25 mysqld_safe mysqld from PID File/var/lib/mysql/target_pc.pid ended
[OK]
Starting MySQL. [OK]
[1]+ done Mysqld_safe--user=mysql--skip-grant-tables--skip-networking
[Root@target_pc software]# mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.6.20
Copyright (c), 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
Can log in normally.
--If the execution statement times is wrong:
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
Solution:
--Reset Password once:
mysql> SET Password=password (' Beijing ')
->;
Query OK, 0 rows Affected (0.00 sec)
Now, if you enter the command again, no more error:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Performance_schema |
| Test |
+--------------------+
4 rows in Set (0.01 sec)