最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談Mysql連接數(shù)據(jù)庫(kù)時(shí)host和user的匹配規(guī)則

 更新時(shí)間:2021年01月05日 14:54:44   作者:翔之天空  
這篇文章主要介紹了淺談Mysql連接數(shù)據(jù)庫(kù)時(shí)host和user的匹配規(guī)則,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

--連接數(shù)據(jù)庫(kù)時(shí),host和user的匹配規(guī)則

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

--host和user的匹配規(guī)則如下:

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

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

--相同的host和user時(shí),排序是不確定的

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.

--查看當(dāng)前的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)
 

--舉個(gè)特殊例子

--建立兩個(gè)特殊用戶如下,一個(gè)用戶名為''(空)、一個(gè)用戶名和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)

--查看當(dāng)前的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用戶時(shí) 會(huì)報(bào)錯(cuò),因?yàn)榘匆陨系捻樞?優(yōu)先匹配到了host為localhost、user為''(空)的用戶,而不是flyremote用戶 (因?yàn)閡ser為''(空)的用戶可以匹配任意用戶名)

[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)

--那就是說(shuō)本地登錄flyremote用戶時(shí), 用匹配到的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 15
Server 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 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.

--查看當(dāng)前用戶連接方式 和 當(dāng)前用戶認(rèn)證方式

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

--用帶入ip的方式登錄flyremote用戶時(shí) 無(wú)問(wèn)題, 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 12
Server 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 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>

--查看當(dāng)前用戶連接方式 和 當(dāng)前用戶認(rèn)證方式

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

--任意用戶、任意host,只要密碼和建立的第二個(gè)空用戶空host的密碼"doubleKong123$"匹配了, 就可以進(jìn)入mysql

--測(cè)試一個(gè)不存在的用戶hahaha

[root@hostmysql-m ~]# mysql -uhahaha -pdoubleKong123$ -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 6
Server 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 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>

--查看當(dāng)前用戶連接方式 和 當(dāng)前用戶認(rèn)證方式

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 來(lái)進(jìn)行安全配置

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

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 have\na user "
      "account created for them. This is intended "
      "only for\ntesting, and to make the "
      "installation go a bit smoother.\nYou should "
      "remove them before moving into a production\n"
      "environment.\n\nRemove 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.\n\n");
 }
 else
 fprintf(stdout, "\n ... skipping.\n\n");
}

補(bǔ)充:mysql 用戶表中多個(gè)host時(shí)的匹配規(guī)則

mysql數(shù)據(jù)庫(kù)中user表的host字段,是用來(lái)控制用戶訪問(wèn)數(shù)據(jù)庫(kù)“權(quán)限”的。

可以使用“%”,表示所有的網(wǎng)段;

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

也可以使用“_”進(jìn)行模糊匹配,表示某個(gè)網(wǎng)段的客戶端可以登錄到mysql服務(wù)器。

如果在user表中存在一個(gè)用戶兩條不同host值的記錄,那么mysql服務(wù)器該如何匹配該用戶的權(quán)限呢?

mysql采用的策略是:當(dāng)服務(wù)器讀取user表時(shí),它首先以最具體的Host值排序(主機(jī)名和IP號(hào)是最具體的) 。有相同Host值的條目首先以最具體的User匹配。

舉例:

如下,有兩條root用戶,那么只有l(wèi)ocalhost的root客戶端可以登錄到mysql服務(wù)器。

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

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

  • MySQL 5.7并發(fā)復(fù)制隱式bug實(shí)例分析

    MySQL 5.7并發(fā)復(fù)制隱式bug實(shí)例分析

    這篇文章主要給大家介紹了關(guān)于MySQL 5.7并發(fā)復(fù)制隱式bug的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用mysql5.7具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • mysql的group_concat函數(shù)使用示例

    mysql的group_concat函數(shù)使用示例

    這篇文章主要介紹了mysql的group_concat函數(shù)使用示例,需要的朋友可以參考下
    2014-04-04
  • MySQL借助DB實(shí)現(xiàn)分布式鎖思路詳解

    MySQL借助DB實(shí)現(xiàn)分布式鎖思路詳解

    這篇文章主要給大家介紹了關(guān)于MySQL借助DB實(shí)現(xiàn)分布式鎖思路的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • MySQL數(shù)據(jù)庫(kù)大小寫(xiě)敏感的問(wèn)題

    MySQL數(shù)據(jù)庫(kù)大小寫(xiě)敏感的問(wèn)題

    今天小編就為大家分享一篇關(guān)于MySQL數(shù)據(jù)庫(kù)大小寫(xiě)敏感的問(wèn)題,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • 詳解Mysql和Oracle之間的誤區(qū)

    詳解Mysql和Oracle之間的誤區(qū)

    mysql 和Oracle 在開(kāi)發(fā)中的使用是隨處可見(jiàn)的,那就簡(jiǎn)單去了解一下這倆款火的不行的數(shù)據(jù)庫(kù)。
    2021-05-05
  • 全面了解MySql中的事務(wù)

    全面了解MySql中的事務(wù)

    下面小編就為大家?guī)?lái)一篇全面了解MySql中的事務(wù)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-06-06
  • mysql:Can''t start server: can''t create PID file: No space left on device

    mysql:Can''t start server: can''t create PID file: No space

    這篇文章主要介紹了mysql啟動(dòng)失敗不能正常啟動(dòng)并報(bào)錯(cuò)Can't start server: can't create PID file: No space left on device問(wèn)題解決方法,需要的朋友可以參考下
    2015-05-05
  • Linux系統(tǒng)下MySQL的初始化和配置指南

    Linux系統(tǒng)下MySQL的初始化和配置指南

    當(dāng)MySQL的系統(tǒng)庫(kù)(mysql系統(tǒng)庫(kù))發(fā)生故障或需要新加一個(gè)mysql實(shí)例時(shí),需要初始化mysql數(shù)據(jù)庫(kù),這篇文章主要給大家介紹了關(guān)于Linux系統(tǒng)下MySQL的初始化和配置指南的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • 一文帶你了解MySQL字符集和比較規(guī)則

    一文帶你了解MySQL字符集和比較規(guī)則

    前段時(shí)間往MySQL中存入emoji表情或生僻字、繁體字時(shí),報(bào)錯(cuò)無(wú)法添加,研究后發(fā)現(xiàn)這是字符集編碼的問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于MySQL字符集和比較規(guī)則的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • MySQL 5.5主從同步設(shè)置筆記分享

    MySQL 5.5主從同步設(shè)置筆記分享

    這篇文章主要介紹了MySQL 5.5主從同步設(shè)置筆記分享,需要的朋友可以參考下
    2014-05-05

最新評(píng)論

防城港市| 德令哈市| 米易县| 凤山市| 松桃| 蒙山县| 潮安县| 封开县| 清远市| 穆棱市| 雅安市| 乌兰察布市| 张家口市| 宝兴县| 句容市| 宣威市| 抚顺县| 周口市| 永春县| 临高县| 仁布县| 大同县| 宝山区| 开封县| 玉林市| 万州区| 大埔区| 中西区| 济源市| 延津县| 景洪市| 洛扎县| 满洲里市| 滁州市| 吉水县| 韶山市| 榆林市| 巴马| 呼伦贝尔市| 宜宾县| 新邵县|