mysql報關於使用者密碼1045(28000),幾種處理方法

datapeng發表於2015-01-21

--mysql5.6,安裝好後進行登入出現
[root@mytest_db usr]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user (using password: NO)

提示密碼問題,再用命令修改,也會出現以下錯誤
[root@mytest_db usr]# mysqladmin -u root password 'petrel'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user (using password: NO)'

這個時候需要用這種方法進行處理
--重啟mysql服務,採用mysqld_safe的方式進行
[root@mytest_db usr]# service mysql stop
Shutting down MySQL...[  OK  ]
[root@mytest_db usr]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 5043
啟動後,就可以直接不用密碼直接進入了,這個時候重新設定密碼
[root@mytest_db usr]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set Password=PASSWORD('petrel') where user = 'root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@mytest_db usr]# service mysql restart
這個時候,再進行登入就沒問題了

[root@mytest_db data]# mysql -uroot -ppetrel
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.19

Copyright (c) 2000, 2014, 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> use mysql;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> grant all privileges  on *.* to    identified   by 'petrel';
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> set PASSWORD=PASSWORD('petrel');
Query OK, 0 rows affected (0.00 sec)

--出現mysql.user表裡面使用者為空時出現
ERROR 1045 (28000): Access denied for user
這個時候可以進行如下處理
刪除這些為空的使用者或者更新為其他使用者名稱
刪除user.user中值為NULL的,或更新NULL為其它值等
mysql> delete from user where user is NULL
Query OK, 1 rows affected (0.00 sec)
或者更新為其它值
mysql> update user set user='mytest' where user is NULL
Query OK, 1 rows affected (0.00 sec)

--如果mysql.user表裡面沒有可以訪問的使用者,也會出現
MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)
這個時候,我們就要採用如下步驟進行
[root@mytest_db usr]# service mysql stop
Shutting down MySQL...[  OK  ]
[root@mytest_db usr]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@mytest_db usr]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> select * from user;
發現沒有使用者
mysql> INSERT INTO user(host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'username', PASSWORD(‘yourpassword'), 'Y', 'Y','Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29371470/viewspace-1409075/,如需轉載,請註明出處,否則將追究法律責任。

相關文章