http://blog.itpub.net/29371470/viewspace-1409075/
http://blog.csdn.net/rosten/article/details/25065897
http://www.jb51.net/article/82421.htm
http://www.linuxidc.com/Linux/2014-07/104244.htm
*********************************************************
--mysql5.6,安裝好后進行登錄出現
[root@mytest_db usr]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
提示密碼問題,再用命令修改,也會出現以下錯誤
[root@mytest_db usr]# mysqladmin -u root password 'petrel'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (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 root@'localhost' 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)
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
解決方法:
MySQL --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';//把空的用戶密碼都修改成非空的密碼就行了。
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: <輸入新設的密碼newpassword>
******************************************************
本文分析了mysql登錄報錯提示:ERROR 1045 (28000)的解決方法。分享給大家供大家參考,具體如下:
一、問題:
公司linux系統的mysql數據庫root用戶設置過密碼,但常常用命令'mysql -u root -p'登錄報錯,有時又能登錄。登錄報錯信息為:
1
2
3
|
[root@localhost ~]
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied
for
user
'root'
@
'localhost'
(using password: YES)
|
二、原因:數據庫中存在空用戶所致
三、解決方法:
1、停用mysql服務:
1
|
# service mysql stop
|
2、輸入命令:
1
|
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
|
3、登入數據庫:
1
|
# mysql -u root mysql
|
4、
1
|
mysql> use mysql;
|
5、
1
|
mysql>
select
user,host,password from user;
|
結果如下:
+------+-----------------------+----------+
| user | host | password |
+------+-----------------------+----------+
| root | % | mima |
| root | localhost.localdomain | mima |
| root | 127.0.0.1 | mima |
| | localhost | |
| | localhost.localdomain | |
+------+-----------------------+----------+
6、將上面查詢出來的空用戶刪除:
1
|
mysql> delete from user where user=
''
;
|
7、退出數據庫:
1
|
mysql> quit
|
8、啟動mysql服務:
1
|
# service mysql start
|
9、重新用命令:
1
|
mysql -u root -p
|
登錄,OK!
更多關於MySQL相關內容感興趣的讀者可查看本站專題:《MySQL事務操作技巧匯總》、《MySQL存儲過程技巧大全》、《MySQL數據庫鎖相關技巧匯總》及《MySQL常用函數大匯總》
希望本文所述對大家MySQL數據庫計有所幫助。
*********************************************
這幾天在MySQL新建用戶后,出現訪問拒絕的問題,錯誤碼為ERROR 1045(28000)。在網上搜索了很久,找到了很多解決辦法,但很遺憾的是這么多辦法沒有一個能解決該問題。雖然出現的錯誤碼28000很多人都遇到過,但原因也有所不同,有的是mysql.user表中沒有信息,有的是root用戶沒有密碼(那就不用密碼登錄),而使用mysql-5.6.19時,mysql.user有用戶信息,root用戶沒有密碼,采用的方法是root用戶登錄時輸入空密碼,登錄成功。使用root用戶創建測試用test,密碼為test,語句如下:
grant all onlogdb.* to test identified by ‘test’;
在命令行輸入mysql -u test –p,輸入密碼test,出現下面的錯誤信息,詳細該錯誤信息很多人在使用MySQL時都遇到過。
ERROR 1045 (28000):Access denied for user 'test'@'localhost' (using password: YES)
解決方法是用root用戶再創建用戶test,密碼test,唯一不同的是指定test登錄的主機為localhost,如下:
grant all onlogdb.* to test@'localhost' identified by 'test';
再次使用test用戶登錄MySQL,成功,如下所示:
使用root用戶登錄MySQL,查看user表中的用戶信息如下,可以發現存在兩個test用戶,host的字段分別為%和localhost,就是前面創建的兩個用戶。
在MySQL中%表示可以在任何主機上登錄MySQL數據庫,那為什么還需要明確創建登錄主機為localhost的用戶呢?這涉及到MySQL安裝時的初始化用戶,匿名用戶以及連接驗證策略等,下面進行深入的分析。
在安裝MySQL時,會默認初始化一些用戶,比如root用戶,以及host字段為localhost,user字段為空的用戶。User字段為空的用戶即為匿名用戶,該用戶的密碼也為空,任何人都可以使用匿名用戶登錄MySQL數據庫,但可以做的事情卻是有限的,比如在命令行直接輸入mysql登錄,可以查看匿名用戶對哪些數據庫有權限:
\
通過上面的圖片可以發現,匿名用戶僅對information_schema和test數據庫有權限。而匿名用戶又是如何影響其他用戶登錄,進而出現28000錯誤的呢?當試圖連接MySQL數據庫時,數據庫根據提供的身份和密碼決定是否接受連接請求,身份由兩部分組成:用戶名和客戶端主機(即輸入mysql命令的主機)。由於host字段中的%匹配任何主機或者host字段包含通配符,就可能出現多個匹配行,服務器必須決定匹配哪一個,解決方案如下:
服務器將user表中的數據讀入內存中,按照host和user字段對行進行排序。
當客戶端試圖連接時,服務器查找已排序的行並使用第一個匹配客戶端主機和用戶名的行,user字段為空表示可以匹配任何用戶。
找到匹配行后,在驗證密碼是否一致,如果一致則登錄成功。
根據上面描述的規則,通過示例來演示為什么必須要創建test@localhost用戶,才能在本地登錄成功。對user表進行排序的結果如下圖所示:
當未創建test@localhost時,該表不包含第一行的記錄。用戶test登錄時,則會匹配到第四行的記錄:host為localhost,user為空,因為user為空可以匹配任何用戶,再去驗證密碼不成功登錄失敗。或者不使用密碼登錄,還是匹配到第四行,但驗證密碼成功,然而匿名用戶只對information_schema和test數據庫有權限,使用其它數據庫時也會失敗,如下所示:
總結一下,當出現28000錯誤時,首先查看user中是否有數據,是否存在匿名用戶。若存在匿名用戶則創建userName@localhost,或者也可以刪除匿名用戶。