關於root(其他)使用者拒絕登陸mysql的處理方法
關於root(其他)使用者拒絕登陸mysql的處理方法
1.1. 關於root(其他)使用者拒絕登陸的處理方法
問題描述:
[root@gflinux3 mysql-install]# mysql -uroot-p
Enter password:
ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: YES)
1.1.1. 跳過許可權表登陸
(1)重啟資料庫,跳過許可權表方式登陸:
[root@gflinux3 mysql-install]# /etc/init.d/mysqldstart --skip-grant-table
Starting MySQL......... [ OK ]
[root@gflinux3 mysql-install]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.5.37-log Sourcedistribution
Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or 'h' for help. Type 'c' toclear the current input statement.
mysql>
(2)更該root密碼
mysql> update user set password=PASSWORD('123456') where USER='root';
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(3)重啟資料庫並重新登陸
[root@gflinux3 mysql-install]#service mysqlrestart
如果問題還是不能解決,繼續向下看。
1.1.2. 遠端可以本地無法登陸
本地無法登陸,但是遠端或者其他使用者可以登陸,root無法登陸。
[root@gflinux3 mysql-install]# mysql -urgf-p
Enter password:
ERROR 1045 (28000): Access denied for user'rgf'@'localhost' (using password: YES)
(1)檢視user表中分佈使用者
mysql> select user,host,password from user;
+------+------+----------------------------------------------------------------------------+
| user | host | password |
+------+------+----------------------------------------------------------------------------+
| root | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | gflinux3 |
| root | 127.0.0.1 |
| root | ::1 |
| rgf | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+---------------------------------------------------------------------------+
2 rows in set (0.00 sec)
(2)檢視檔案/etc/hosts
[root@gflinux3 mysql-install]# vi/etc/hosts
# Do not remove the following line, orvarious programs
# that require network functionality willfail.
127.0.0.1 gflinux3 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.6.103 gflinux3
(3)分析
mysql初始化時root使用者根據hosts配置檔案中的主機及主機名在user表中產生上述記錄(127.0.0.1,gflinux3,localhost,::1,192.168.6.103),而安裝完資料庫,使用mysqladmin初始化密碼時,是對user表中localhost,即上述表中第一條記錄做的修改:
mysql> select user,host,password from user;
+------+------+----------------------------------------------------------------------------+
| user | host | password |
+------+------+----------------------------------------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+---------------------------------------------------------------------------+
而其他“主機”密碼都為空,這時再以root及其密碼登陸時當然無法登陸。
更值得提醒的時,這些“主機”的存在,在安全上及其危險。
(4)處理方法
首先,修改hosts檔案為:
[root@gflinux3 mysql-install]# vi/etc/hosts
# Do not remove the following line, orvarious programs
# that require network functionality willfail.
127.0.0.1 gflinux3 localhost.localdomain localhost
#::1 localhost6.localdomain6 localhost6
192.168.6.103 gflinux3
其次,刪除user表中所有相關主機記錄。
mysql>delete from user where hostin('gflinux3','127.0.0.1','::1','localhost');
Query OK,5 rows affected (0.01 sec)
mysql>update privileges;
mysql>select user,host,password from user;
+------+------+-------------------------------------------+
| user |host | password |
+------+------+-------------------------------------------+
| root |% |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
|rgf | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
+------+------+-------------------------------------------+
2 rows inset (0.00 sec)
(3)登陸驗證
[root@gflinux3mysql-install]# mysql -uroot -p
Enterpassword:
Welcometo the MySQL monitor. Commands end with; or g.
YourMySQL connection id is 22
Serverversion: 5.5.37-log Source distribution
Copyright(c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle isa 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>
當然,不建議使root使用者從遠端連線,這樣很危險,因此,作如下操作取消使用root遠端連線:
mysql>update user set host='localhost' where user='root';
Query OK,1 row affected (0.00 sec)
Rowsmatched: 1 Changed: 1 Warnings: 0
mysql>flush privileges;
Query OK,0 rows affected (0.00 sec)
1.1.3. 關於登陸
(1)如果host欄位更新為localhost:
如下方式可以登陸成功:
[root@gflinux3mysql-install]# mysql -uroot -p
[root@gflinux3mysql-install]# mysql -hlocalhost -uroot -p
但是如下方式無法登陸:
[root@gflinux3mysql-install]# mysql -h127.0.0.1 -uroot -p
[root@gflinux3mysql-install]# mysql -h gflinux3 -uroot -p
[root@gflinux3mysql-install]# mysql -h192.168.6.103 -uroot -p
原因是user表中host欄位值只有記錄localhost。其他登陸方式無法在user表中得到認證。
(2)如果host欄位更新為%
所有的方式都可以登陸:
[root@gflinux3mysql-install]# mysql -uroot -p
[root@gflinux3mysql-install]# mysql -hlocalhost -uroot -p
[root@gflinux3mysql-install]# mysql -h127.0.0.1 -uroot -p
[root@gflinux3mysql-install]# mysql -h gflinux3 -uroot -p
[root@gflinux3mysql-install]# mysql -h192.168.6.103 -uroot -p
原因是user表中host欄位值匹配所有主機。(127.0.0.1,gflinux3,localhost,::1,192.168.6.103)這些都是指的一臺主機,在user表中可以透過認證,從而可以登陸。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28258625/viewspace-1608816/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SYS使用者可以登入,其他使用者無法登陸的問題處理
- Ubuntu ssh伺服器拒絕密碼(使用root登入)Ubuntu伺服器密碼
- 透過linux-PAM實現禁止root使用者登陸的方法Linux
- mysql中root使用者誤刪的處理辦法MySql
- MySQL 5.6 關於登陸的初始化設定MySql
- root和其他使用者不能登入的解決方案
- ssh只能遠端登陸到普通使用者,不能以root遠端登陸
- cqrs架構中,使用者登陸如何處理啊架構
- mysql 8.0忘記root使用者密碼處理MySql密碼
- 如何讓mysql以root使用者遠端登陸(remote login)mysql資料庫MySqlREM資料庫
- MySQL 關於毫秒的處理薦MySql
- CentOS7忘記mysql的root密碼_處理方法.CentOSMySql密碼
- mysql報關於使用者密碼1045(28000),幾種處理方法MySql密碼
- root使用者ssh無法登陸到伺服器伺服器
- 關於ORACLE登陸認證Oracle
- 關於MySQL下修改root使用者密碼的解決MySql密碼
- MySQL命令列登陸,遠端登陸MySQLMySql命令列
- ubuntu 12.04 root使用者登入的方法Ubuntu
- mysql的root使用者無法給普通使用者授權問題處理MySql
- ssh登陸伺服器locale告警(-bash: warning: setlocale:)的處理方法伺服器
- MySQL忘記root密碼後的處理MySql密碼
- win10 1909安裝程式資訊提示拒絕訪問處理方法Win10
- 關於Oracle死鎖處理方法Oracle
- 【問題處理】MySQL忘記root密碼的處理辦法MySql密碼
- Java--- 關於null的處理若干方法JavaNull
- fedora 17的root不能圖形介面登陸
- 關於jsp拒絕訪問的問題,謝謝大家JS
- localhost拒絕訪問的解決方法localhost
- vsftp無法使用root登陸的問題FTP
- root使用者執行root.sh失敗怎麼處理
- MySQL5.7忘記root密碼處理MySql密碼
- 關於微信小程式使用者拒絕授權後不再彈出授權視窗微信小程式
- 對於putty連線ubuntu被拒絕的一個解決方法Ubuntu
- 使用者密碼包含特殊字元時的登陸方法密碼字元
- LINUX忘記ROOT使用者密碼處理方法(linux單使用者模式)Linux密碼模式
- 【如何拒絕Win10_1703更新,且不影響其他更新】Win10
- 關於ssh登陸很慢的解決辦法【轉】
- 影象處理中關於孔洞填充的方法總結