When the root user logs on to MySQL, the system finds that the password is incorrect.
[Root @ gk ~] # Mysql-u root-p
Enter password:
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)
Solution
1. stop the mysqld service
[Root @ gk ~] # Service mysqld stop
Stop mysqld: [OK]
2. Execute mysqld_safe -- skip-grant-tables
[Root @ gk ~] # Mysqld_safe -- skip-grant-tables
140607 22:21:50 mysqld_safe Logging to '/var/log/mysqld. log '.
140607 22:21:50 mysqld_safe Starting mysqld daemon with databases from/var/lib/mysql
3. log on to mysql
[Root @ gk ~] # Mysql
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 1
Server version: 5.1.71 Source distribution
Copyright (c) 2000,201 3, 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.
4. switch to the mysql database
Mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
5.Update password
Mysql> update user set password = password ('redhat') where user = 'root ';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3 Changed: 2 Warnings: 0
Mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Mysql> exit
Bye
6. restart the mysqld service.
[Root @ gk ~] # Service mysqld restart
Stop mysqld: [OK]
Starting mysqld: [OK]
7. log on with the new password
[Root @ gk ~] # Mysql-u root-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or/g.
Your MySQL connection id is 2
Server version: 5.1.71 Source distribution
Copyright (c) 2000,201 3, 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.
Mysql>