日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql登陆案例_Mysql用户登陆验证过程 案例

發(fā)布時(shí)間:2023/12/16 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql登陆案例_Mysql用户登陆验证过程 案例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Mysql用戶登陸驗(yàn)證過程 & 案例

Mysql用戶登陸驗(yàn)證過程:

1、Mysql server將user表讀入到內(nèi)存中,然后排序,排序原則下面會(huì)講

2、客戶端嘗試連接Mysql服務(wù)器,服務(wù)器掃描內(nèi)存中排序過后的user表的條目

3、Mysql服務(wù)器采納第一行匹配的客戶端名和用戶名,然后驗(yàn)證通過

Mysql服務(wù)器內(nèi)存中user表排序原則:

1、最具象(most-specific)的條目放在最前面。

2、user表的host列,文本主機(jī)名(Literal host names)和IP地址是最具象的。子網(wǎng)掩碼的方式,如192.168.1.0/255.255.255.0的具象程度等同于192.168.1.13,都是最具象的;子網(wǎng)掩碼192.168.1.0/255.255.255.0的具象程度高于192.168.1.%。'%'是最不具象的,優(yōu)先級排在后面;空字符串''意思是any host,具象級別排在'%'之后。

3、host值相同,最具象的值排在最前面;user值為空,以為著any user,是最不具象的。

總結(jié):

1、user表中的host和user列按照具象程度排序加載到內(nèi)存中,最具象的排在最前面。

2、host具象程度相同時(shí),再去按照user的具象程度從高到底匹配;若沒有匹配上,那么轉(zhuǎn)移到次具象的host繼續(xù)匹配,直至匹配上為止;若沒有匹配上,那么登錄驗(yàn)證宣告失敗。

案例:

測試環(huán)境中,三臺(tái)主機(jī)組成Master slave集群,gp-s2是master,gp-s1和gp-s3是slave,并且這三臺(tái)服務(wù)器都在同一個(gè)網(wǎng)段。

gp-s2 Master上的user表如下,rep1用戶允許 10.9.15.% 這個(gè)網(wǎng)段都訪問gp-s2。

+-------------------------+-------+

| host ? ? ? ? ? ? ? ? ? ?| user ?|

+-------------------------+-------+

| % ? ? ? ? ? ? ? ? ? ? ? | root ?|

| % ? ? ? ? ? ? ? ? ? ? ? | test3 |

| 10.9.15.% ? ? ? ? ? ? ? | rep1 ?|

| 10.9.15.% ? ? ? ? ? ? ? | test ?|

| 10.9.15.% ? ? ? ? ? ? ? | test2 |

| 10.9.15.0/255.255.255.0 | wang ?|

| 10.9.15.18 ? ? ? ? ? ? ?| root ?|

| 127.0.0.1 ? ? ? ? ? ? ? | root ?|

| ::1 ? ? ? ? ? ? ? ? ? ? | root ?|

| gp-master ? ? ? ? ? ? ? | root ?|

| gp-s1 ? ? ? ? ? ? ? ? ? | ? ? ? |

| gp-s1 ? ? ? ? ? ? ? ? ? | root ?|

| gp-s1 ? ? ? ? ? ? ? ? ? | test ?|

| gp-s3 ? ? ? ? ? ? ? ? ? | test ?|

| localhost ? ? ? ? ? ? ? | ? ? ? |

| localhost ? ? ? ? ? ? ? | root ?|

+-------------------------+-------+

16 rows in set (0.00 sec)

使用rep1用戶在gp-s1上無法登錄gp-s2

[root@gp-s1 ~]# mysql -urep1 -p123456 -h gp-s2

ERROR 1045 (28000): Access denied for user 'rep1'@'gp-s1' (using password: YES)

使用rep1用戶在gp-s2上能夠登錄gp-s2

[root@gp-s3 ~]# ?mysql -urep1 -p123456 -h gp-s2

Welcome to the MySQL monitor. ?Commands end with ; or \g.

Your MySQL connection id is 17

Server version: 5.5.48-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

這是一個(gè)很奇怪的問題,相同用戶、在相同網(wǎng)段,gp-s1可以登錄,gp-s3不可以登錄。

試著在master上給rep1用戶加上新權(quán)限

mysql> grant replication slave on *.* to 'rep1'@'10.9.15.19' identified by "123456";

這次在gp-s1主機(jī)上登錄master可以順利登錄,但是走的條目是'10.9.15.19',而不是'10.9.15.%'

[root@gp-s1 ~]# mysql -urep1 -p123456 -h gp-s2

Welcome to the MySQL monitor. ?Commands end with ; or \g.

Your MySQL connection id is 34

Server version: 5.5.48-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

mysql>

mysql> select user(),current_user();

+------------+-----------------+

| user() ? ? | current_user() ?|

+------------+-----------------+

| rep1@gp-s1 |rep1@10.9.15.19?|

+------------+-----------------+

1 row in set (0.00 sec)

gp-s3登錄則是走的正常條目'10.9.15.%'

[root@gp-s3 ~]# mysql -urep1 -p123456 -h gp-s2

Welcome to the MySQL monitor. ?Commands end with ; or \g.

Your MySQL connection id is 35

Server version: 5.5.48-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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 user(),current_user();

+----------------+----------------+

| user() ? ? ? ? | current_user() |

+----------------+----------------+

| rep1@10.9.15.2 |?rep1@10.9.15.%?|

+----------------+----------------+

1 row in set (0.00 sec)

這說明gp-s1到gp-s2網(wǎng)絡(luò)是沒有問題的。

采用排錯(cuò)法,gp-s3正常,那么比對gp-s1和gp-s3在user表中的區(qū)別,最后找到了根源。

+-------------------------+----------+-------------------------------------------+

| host ? ? ? ? ? ? ? ? ? ?| user ? ? | password ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|

+-------------------------+----------+-------------------------------------------+

| % ? ? ? ? ? ? ? ? ? ? ? | root ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| % ? ? ? ? ? ? ? ? ? ? ? | test3 ? ?| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.% ? ? ? ? ? ? ? | rep1 ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.% ? ? ? ? ? ? ? | test ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.% ? ? ? ? ? ? ? | test2 ? ?| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.% ? ? ? ? ? ? ? | wchbsync | *55D02D8B1D286B078AC8DC9CD05E2D5D80906F3F |

| 10.9.15.0/255.255.255.0 | wang ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.18 ? ? ? ? ? ? ?| root ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.19 ? ? ? ? ? ? ?| rep1 ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 10.9.15.19 ? ? ? ? ? ? ?| rep2 ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 127.0.0.1 ? ? ? ? ? ? ? | root ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

| ::1 ? ? ? ? ? ? ? ? ? ? | root ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

| gp-master ? ? ? ? ? ? ? | root ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| gp-s1 ? ? ? ? ? ? ? ? ? | ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |????問題出在這里

| gp-s1 ? ? ? ? ? ? ? ? ? | root ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

| gp-s1 ? ? ? ? ? ? ? ? ? | test ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| gp-s3 ? ? ? ? ? ? ? ? ? | test ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| localhost ? ? ? ? ? ? ? | ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

| localhost ? ? ? ? ? ? ? | root ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+-------------------------+----------+-------------------------------------------+

將這一行刪掉,問題解決。

那么為什么會(huì)出現(xiàn)這種問題呢??

因?yàn)間p-s1登陸gp-s2,首先去匹配host,按照具象程度,這3個(gè)條目匹配到。

| gp-s1 ? ? ? ? ? ? ? ? ? | ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |????問題出在這里

| gp-s1 ? ? ? ? ? ? ? ? ? | root ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

| gp-s1 ? ? ? ? ? ? ? ? ? | test ? ? | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

匹配到host gp-s1之后,再按照具象程度匹配user,user列沒有rep1用戶,最后只能匹配空值'',空值意味著any user。對于用戶空值并且密碼同時(shí)為空的情況,意味著無法遠(yuǎn)程登陸。

**特別說明

如果用戶名為空,但是密碼不為空的情況。遠(yuǎn)程用戶登錄,只要密碼正確,無論用戶怎么寫,都能登錄。

這里也要特別注意,對于用戶空值的情況,一定要及時(shí)刪除,避免出現(xiàn)不必要的麻煩!

轉(zhuǎn)載請注明:

十字螺絲釘

http://blog.chinaunix.net/uid/23284114.html

QQ:463725310

E-MAIL:houora#gmail.com(#請自行替換為@)

總結(jié)

以上是生活随笔為你收集整理的mysql登陆案例_Mysql用户登陆验证过程 案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。