成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

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

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

瀏覽:7日期: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 數據庫
相關文章:
成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久
精品视频一区二区不卡| 色老汉av一区二区三区| 久久激情一区| 亚洲黄网站在线观看| 亚洲日本视频| 欧美激情资源网| 97国产一区二区| 欧美大片在线观看一区二区| 老司机精品视频线观看86| 性欧美暴力猛交另类hd| 一区二区在线观看免费视频播放| 91在线porny国产在线看| 日韩免费看的电影| 成人午夜在线播放| 日韩美一区二区三区| 国产精品123| 欧美一区二区在线观看| 国产盗摄一区二区| 日韩视频国产视频| 粉嫩高潮美女一区二区三区| 日韩欧美二区三区| 成人免费高清在线| 精品久久久影院| 色综合中文综合网| 欧美国产在线观看| 欧美视频在线观看| 国产精品国产三级国产a| 伊人成人在线| 亚洲欧美日韩国产一区二区三区 | 亚洲图片在线| 自拍偷拍国产精品| 亚洲婷婷在线| 亚洲精品免费看| 国产精品日韩欧美一区| 亚洲va欧美va国产va天堂影院| 亚洲综合电影一区二区三区| 午夜精品久久久久久久99樱桃| 色天使色偷偷av一区二区| 久久福利视频一区二区| 6080日韩午夜伦伦午夜伦| 国产不卡视频在线观看| 久久久久九九视频| 亚洲高清在线| 婷婷六月综合亚洲| 欧美精品久久一区| k8久久久一区二区三区| 国产丝袜在线精品| 亚洲欧洲在线一区| 婷婷夜色潮精品综合在线| 91麻豆精品国产91久久久久久久久 | 91啪在线观看| 亚洲男人的天堂在线观看| 久久亚洲图片| 国产99精品国产| 国产精品视频观看| 亚洲影院免费| 国产一区二区三区在线观看精品| 亚洲精品一区二区三区在线观看 | 狠狠色噜噜狠狠狠狠色吗综合| 亚洲一区二区免费视频| 欧美日韩国产首页| 99精品在线免费| 自拍视频在线观看一区二区| 色婷婷综合在线| 国产高清精品网站| 国产日韩影视精品| 国产日韩精品久久| 蜜臀av性久久久久蜜臀aⅴ流畅| 欧美一级一区二区| 国产精品九九| 日韩一区精品视频| 精品久久久久久无| 99热免费精品| 精油按摩中文字幕久久| 久久久精品一品道一区| 国产精品一区在线播放| 国产精品77777| 中文字幕一区二区三区四区| 在线观看日韩一区| 色综合天天综合网天天看片| 亚洲主播在线播放| 欧美一区二区视频在线观看2022| 韩国av一区| 精品在线一区二区| 久久一二三国产| 国产伦精品一区二区| 国产成人综合视频| 亚洲乱码国产乱码精品精98午夜| 欧美日韩视频在线观看一区二区三区 | 99在线精品观看| 亚洲成人黄色影院| 精品久久久久一区| 性色av一区二区怡红| 国产伦精品一区二区三区在线观看| 国产精品日韩精品欧美在线| 日本乱码高清不卡字幕| 91美女在线视频| 蜜臀av一级做a爰片久久| 中文字幕欧美日韩一区| 在线中文字幕不卡| 午夜电影亚洲| 久久精品久久99精品久久| 国产精品伦理一区二区| 欧美日韩国产123区| 精品成人国产| 国产很黄免费观看久久| 亚洲精品视频自拍| 精品久久一区二区| 亚欧美中日韩视频| 91一区在线观看| 日韩激情中文字幕| 国产精品理伦片| 欧美久久久久久久久久| 国产一区二区三区久久| 99精品欧美一区二区三区综合在线| 日韩不卡一区二区三区| 国产精品欧美极品| 欧美一区二区三区公司| 久久av一区二区三区| 欧美婷婷在线| 国产成人亚洲精品青草天美 | 日韩在线观看一区二区| 国产精品大尺度| 欧美一区二区播放| 91成人免费网站| 欧美亚洲色图校园春色| 亚洲午夜精品久久久久久app| 成人免费视频播放| 久久国产日韩欧美精品| 亚洲国产成人va在线观看天堂| 国产亚洲成年网址在线观看| 91麻豆精品国产无毒不卡在线观看| 国产伦精品一区二区三区视频孕妇 | 日本不卡123| 亚洲日本在线看| 国产日韩精品视频一区| 日韩欧美国产综合一区 | 久久久影院官网| 欧美理论电影在线| 久久中文精品| 在线综合亚洲| 欧美日韩亚洲一区| 99久久99久久精品免费观看| 国产成人在线网站| 国产中文字幕精品| 青青草国产成人99久久| 亚洲国产精品久久人人爱| 一卡二卡欧美日韩| 日本一区二区视频在线观看| 精品人在线二区三区| 欧美日韩国产一级| 在线亚洲高清视频| 久久精品人人| 亚洲一区二区三区午夜| 99一区二区| 狠狠色狠狠色综合日日tαg| 93久久精品日日躁夜夜躁欧美| 国产成人精品在线看| 黄页视频在线91| 久久精品国产久精国产| 日本不卡一区二区三区高清视频| 一区二区三区.www| 亚洲欧美欧美一区二区三区| 中文字幕在线不卡| 国产精品久久精品日日| 亚洲国产精品二十页| 国产色产综合色产在线视频| 久久精品男人天堂av| 欧美videofree性高清杂交| 日韩美女视频一区二区在线观看| 91精品国产乱码久久蜜臀| 欧美四级电影网| 欧美午夜寂寞影院| 欧美三级乱人伦电影| 欧美日精品一区视频| 欧美日韩国产综合一区二区 | 日韩女优av电影| 欧美电影免费观看高清完整版| 91精品国产综合久久香蕉的特点 | 久久精品国产在热久久| 久久aⅴ国产欧美74aaa| 精品一区二区三区在线播放| 久草在线在线精品观看| 美女爽到高潮91| 国产综合色产在线精品| 国内外成人在线视频| 国产一区二区精品久久| 高潮精品一区videoshd| 不卡高清视频专区| 91免费版在线看| 一区二区视频欧美| 国产亚洲网站| 久久久国产精品一区二区中文| 久久一综合视频| 欧美探花视频资源| 欧美一区二区三区日韩| 久久女同性恋中文字幕| 中文字幕精品在线不卡| 有坂深雪av一区二区精品| 亚洲一区二区视频在线|