日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

淺談Mysql連接數據庫時host和user的匹配規則

瀏覽:50日期:2023-10-07 08:43:07

--連接數據庫時,host和user的匹配規則

官方文檔:https://dev.mysql.com/doc/refman/5.7/en/connection-access.html

--host和user的匹配規則如下:

--是host為明確的最先匹配,host帶%模糊的時候最后匹配,但host為’’(空)位于%之后才匹配

--相同的host時候,比較user為明確的最先匹配,user為’’(空)最后匹配

--相同的host和user時,排序是不確定的

When multiple matches are possible, the server must determine which of them to use. It resolves this issue as follows: Whenever the server reads the user table into memory, it sorts the rows. When a client attempts to connect, the server looks through the rows in sorted order. The server uses the first row that matches the client host name and user name. The server uses sorting rules that order rows with the most-specific Host values first. Literal host names and IP addresses are the most specific. (The specificity of a literal IP address is not affected by whether it has a netmask, so 198.51.100.13 and 198.51.100.0/255.255.255.0 are considered equally specific.) The pattern ’%’ means “any host” and is least specific. The empty string ’’ also means “any host” but sorts after ’%’. Rows with the same Host value are ordered with the most-specific User values first (a blank User value means “any user” and is least specific). For rows with equally-specific Host and User values, the order is nondeterministic.

--查看當前的host及用戶信息匹配順序,先host順序匹配、后user順序匹配

mysql> SELECT authentication_string, host, user,account_locked FROM mysql.USER ORDER BY host desc ,user desc;+-------------------------------------------+--------------+---------------+----------------+| authentication_string | host | user | account_locked |+-------------------------------------------+--------------+---------------+----------------+| *511C0A408C5065XXEC90D60YYA1AB9437281AF28 | localhost | root | N || *THISISNOTAVALIXXASSWORDYYATCANBEUSEDHERE | localhost | mysql.sys | Y || *THISISNOTAVALIXXASSWORDYYATCANBEUSEDHERE | localhost | mysql.session | Y || *485CE31BA547A4XXC047659YY10DF200F361CD4E | localhost | bkpuser | N || *7B502777D8FF69XX4B56BC2YY2867F4B47321BA8 | 192.168.56.% | repl | N || *AECCE73463829AXX3968838YYF6F85E43C3F169C | % | flyremote | N || *566AC8467DAAAEXXE247AE7YY0A770E9B97D9FB0 | | flylocal | N |+-------------------------------------------+--------------+---------------+----------------+8 rows in set (0.00 sec)

--舉個特殊例子

--建立兩個特殊用戶如下,一個用戶名為’’(空)、一個用戶名和host都為’’(空)

mysql> create user ’’@’localhost’ identified by 'Kong123$';Query OK, 0 rows affected (0.00 sec) mysql> create user ’’@’’ identified by 'doubleKong123$'; Query OK, 0 rows affected (0.00 sec)

--查看當前的host及用戶信息匹配順序,先host順序匹配、后user順序匹配

mysql> SELECT authentication_string, host, user,account_locked FROM mysql.USER ORDER BY host desc ,user desc;+-------------------------------------------+--------------+---------------+----------------+| authentication_string | host | user | account_locked |+-------------------------------------------+--------------+---------------+----------------+| *511C0VVV8C5065CBEC90D6TTTT1AB9437281AF28 | localhost | root | N || *THISIVVVTAVALIDPASSWORTTTTTCANBEUSEDHERE | localhost | mysql.sys | Y || *THISIVVVTAVALIDPASSWORTTTTTCANBEUSEDHERE | localhost | mysql.session | Y || *485CEVVVA547A48CC04765TTTT0DF200F361CD4E | localhost | bkpuser | N || *256D7VVV91F7363EBDADEFTTTTB74B2B318746FC | localhost | | N || *7B502VVVD8FF69164B56BCTTTT867F4B47321BA8 | 192.168.56.% | repl | N || *AECCEVVV63829A5F396883TTTT6F85E43C3F169C | % | flyremote | N || *566ACVVV7DAAAE79E247AETTTTA770E9B97D9FB0 | | flylocal | N || *AE162VVV68403D1D98A4C9TTTT50A508B8C56F3F | | | N |+-------------------------------------------+--------------+---------------+----------------+9 rows in set (0.00 sec)

--這樣本地登錄flyremote用戶時 會報錯,因為按以上的順序 優先匹配到了host為localhost、user為’’(空)的用戶,而不是flyremote用戶 (因為user為’’(空)的用戶可以匹配任意用戶名)

[root@hostmysql-m mysql]# mysql -uflyremote -pFlyremote123$mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user ’flyremote’@’localhost’ (using password: YES)

--那就是說本地登錄flyremote用戶時, 用匹配到的host為localhost、user為’’(空)的密碼 Kong123$ ,就可以正常登陸了

[root@hostmysql-m mysql]# mysql -uflyremote -pKong123$mysql: [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 15Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ’help;’ or ’h’ for help. Type ’c’ to clear the current input statement.

--查看當前用戶連接方式 和 當前用戶認證方式

mysql> select user(),CURRENT_USER();+---------------------+----------------+| user() | CURRENT_USER() |+---------------------+----------------+| flyremote@localhost | @localhost |+---------------------+----------------+1 row in set (0.06 sec)

--用帶入ip的方式登錄flyremote用戶時 無問題, ip匹配到了% ,user匹配到了flyremote

[root@hostmysql-m mysql]# mysql -uflyremote -pFlyremote123$ -h127.11.22.33 mysql: [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 12Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ’help;’ or ’h’ for help. Type ’c’ to clear the current input statement. mysql>

--查看當前用戶連接方式 和 當前用戶認證方式

mysql> select user(),CURRENT_USER();+------------------------+----------------+| user() | CURRENT_USER() |+------------------------+----------------+| flyremote@127.11.22.33 | flyremote@% |+------------------------+----------------+1 row in set (0.00 sec)

--任意用戶、任意host,只要密碼和建立的第二個空用戶空host的密碼'doubleKong123$'匹配了, 就可以進入mysql

--測試一個不存在的用戶hahaha

[root@hostmysql-m ~]# mysql -uhahaha -pdoubleKong123$ -h127.11.22.33mysql: [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 6Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type ’help;’ or ’h’ for help. Type ’c’ to clear the current input statement. mysql>

--查看當前用戶連接方式 和 當前用戶認證方式

mysql> select user(),CURRENT_USER();+---------------------+----------------+| user() | CURRENT_USER() |+---------------------+----------------+| hahaha@127.11.22.33 | @ |+---------------------+----------------+1 row in set (0.01 sec)--解決方案:

1、手工刪除空用戶和空host用戶確保安全

或者

2、使用 mysql_secure_installation 來進行安全配置

--安全配置如下,其中有刪除匿名用戶的操作

This program enables you to improve the security of your MySQL installation in the following ways: You can set a password for root accounts. You can remove root accounts that are accessible from outside the local host. You can remove anonymous-user accounts. You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.

--刪除匿名用戶的源碼 mysql_secure_installation.cc 如下:

//Remove anonymous users remove_anonymous_users(); /** Removes all the anonymous users for better security.*/void remove_anonymous_users(){ int reply; reply= get_response((const char *) 'By default, a MySQL installation has an ' 'anonymous user,nallowing anyone to log ' 'into MySQL without having to havena user ' 'account created for them. This is intended ' 'only forntesting, and to make the ' 'installation go a bit smoother.nYou should ' 'remove them before moving into a productionn' 'environment.nnRemove anonymous users? ' '(Press y|Y for Yes, any other key for No) : ', ’y’); if (reply == (int) ’y’ || reply == (int) ’Y’) { const char *query; query= 'SELECT USER, HOST FROM mysql.user WHERE USER=’’'; if (!execute_query(&query, strlen(query))) DBUG_PRINT('info', ('query success!')); MYSQL_RES *result= mysql_store_result(&mysql); if (result) drop_users(result); mysql_free_result(result); fprintf(stdout, 'Success.nn'); } else fprintf(stdout, 'n ... skipping.nn');}

補充:mysql 用戶表中多個host時的匹配規則

mysql數據庫中user表的host字段,是用來控制用戶訪問數據庫“權限”的。

可以使用“%”,表示所有的網段;

也可以使用具體的ip地址,表示只有該ip的客戶端才可以登錄到mysql服務器;

也可以使用“_”進行模糊匹配,表示某個網段的客戶端可以登錄到mysql服務器。

如果在user表中存在一個用戶兩條不同host值的記錄,那么mysql服務器該如何匹配該用戶的權限呢?

mysql采用的策略是:當服務器讀取user表時,它首先以最具體的Host值排序(主機名和IP號是最具體的) 。有相同Host值的條目首先以最具體的User匹配。

舉例:

如下,有兩條root用戶,那么只有localhost的root客戶端可以登錄到mysql服務器。

| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B || root | % | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: MySQL 數據庫
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产精品视频一区视频二区| 久久久精品五月天| 91精品高清| 首页国产欧美久久| 日本不卡视频一二三区| 国产精品15p| 亚洲国产欧美日本视频| 激情久久婷婷| 中文字幕日本一区| 国产精品流白浆在线观看| 精品一区二区三区四区五区| 三上悠亚国产精品一区二区三区| 欧美日韩国产探花| 免费福利视频一区二区三区| 女人天堂亚洲aⅴ在线观看| 亚洲精品大全| 超级白嫩亚洲国产第一| 亚洲少妇在线| 国产亚洲一卡2卡3卡4卡新区| 国产一区二区三区视频在线| 亚洲欧美日韩高清在线| 偷拍亚洲精品| 欧美www视频在线观看| 中文在线一区| 麻豆精品视频在线观看免费| 不卡中文字幕| 国产精品白丝久久av网站| 韩国精品主播一区二区在线观看| 国产精品美女久久久浪潮软件| 国产欧美日韩影院| 不卡一区2区| 久久精品国产成人一区二区三区| 亚洲精品网址| 精品亚洲成人| 亚洲精品大全| 久久精品在线| 蜜桃精品视频| 一区二区国产在线| 桃色av一区二区| 欧美精品影院| 亚洲免费在线| 国产精品伦理久久久久久| 亚洲精选久久| 亚洲午夜天堂| 国产精品任我爽爆在线播放| 国产精品日本| 色综合www| 国产激情综合| 最新国产精品久久久| 久久精品一区二区不卡| 国产精品亚洲综合久久| 麻豆亚洲精品| 国产v综合v| 国产欧美啪啪| 亚洲免费一区三区| 亚洲第一区色| 福利一区视频| 国产精品s色| 亚洲一区av| 亚洲天堂成人| 免费高潮视频95在线观看网站| 国产亚洲电影| 一区二区三区四区精品视频| 国产精品av久久久久久麻豆网| 久久麻豆视频| 久久狠狠久久| 青青国产91久久久久久| 综合激情网站| 六月婷婷一区| 久久国产精品99国产| 欧美日韩国产高清| 久久精品亚洲欧美日韩精品中文字幕| 久久免费精品| 国产精品一区二区精品视频观看| 亚洲尤物av| 在线精品观看| 综合国产在线| 亚洲欧美一级| 日韩精品福利一区二区三区| 伊人www22综合色| 先锋影音久久久| 欧美日韩国产一区精品一区| 精品一区免费| 日韩午夜黄色| 视频一区二区欧美| 蜜桃久久久久久久| 亚洲一级大片| 日韩不卡一区二区| 91成人精品在线| 欧美日本不卡高清| 国产精品一区高清| 国产精品白丝av嫩草影院| 国产女人18毛片水真多18精品| 国产欧美成人| 久久香蕉精品香蕉| 日韩在线观看一区| 国产精品99免费看| 视频一区视频二区中文字幕| 亚洲另类av| 国产日韩欧美一区二区三区在线观看 | 美女视频黄 久久| 国产精品久久久久久av公交车| 老色鬼精品视频在线观看播放| 精品国产成人| 久久精品主播| 蜜桃久久av| 日韩精品电影一区亚洲| 欧美一级一区| 久久久久久久欧美精品| 国产成人免费| 91九色精品| 亚洲视频国产| 国产乱人伦丫前精品视频| 国产精品久久国产愉拍| 日韩1区2区| 亚洲女同一区| 日本不卡视频在线| 精品99在线| 啪啪国产精品| 久久福利毛片| 国产精品男女| 欧美日韩免费观看视频| 9色国产精品| 国产日产精品_国产精品毛片 | 国产专区一区| 亚洲精品欧洲| 国产福利片在线观看| 中国女人久久久| 国产亚洲第一伦理第一区| 开心激情综合| 亚洲激情国产| 国产福利一区二区精品秒拍| 日韩中文首页| 综合亚洲视频| 91综合网人人| 亚洲免费专区| 日韩黄色大片网站| 少妇精品久久久| zzzwww在线看片免费| 蜜臀国产一区二区三区在线播放 | 亚洲毛片网站| 成人免费一区| 久久最新视频| 国产精品久久观看| 中文字幕免费精品| 免费高潮视频95在线观看网站| 蜜臀精品久久久久久蜜臀| 国产 日韩 欧美 综合 一区| 日本大胆欧美人术艺术动态| 四虎国产精品免费观看| 亚洲一二av| 日韩三区在线| 国产黄色一区| 综合国产视频| 欧美1级日本1级| 成人在线观看免费视频| 日韩专区欧美专区| 精精国产xxxx视频在线野外| 日本aⅴ精品一区二区三区| 欧美高清不卡| av资源中文在线天堂| 欧美一区影院| 日韩一区精品视频| 久久国产电影| 国产aa精品| 国产日本久久| 亚洲欧美专区| aⅴ色国产欧美| 三级精品视频| 日韩av在线播放网址| 国产日韩一区二区三区在线| 伊人久久亚洲美女图片| 日韩黄色大片| 精品九九久久| 国产精品久久久亚洲一区| 麻豆9191精品国产| 久久久久蜜桃| av中文资源在线资源免费观看| 国产一卡不卡| 日韩三级久久| 在线观看一区| 午夜宅男久久久| 婷婷色综合网| 久久中文视频| 欧美日韩国产v| 成午夜精品一区二区三区软件| 日韩精品欧美精品| 一区二区亚洲视频| 视频一区欧美精品| 国产亚洲高清视频| 欧美日韩国产一区二区三区不卡| 日韩在线免费| 欧洲av不卡| 91精品婷婷色在线观看| 亚洲天堂免费电影| 久久久久一区| 欧美日韩在线播放视频| 亚洲高清av| 999在线观看精品免费不卡网站| 欧美理论视频|