好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 淺談Mysql連接數據庫時host和user的匹配規則

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

熱門標簽:常州電銷外呼系統一般多少錢 云南語音外呼系統平臺 沃克斯電梯外呼線路圖 天智外呼系統 400電話鄭州申請 地圖標注被騙三百怎么辦 北京人工外呼系統價錢 房產智能外呼系統品牌 福州呼叫中心外呼系統哪家好

--連接數據庫時,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 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.

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

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

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

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.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>

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

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 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");
}

補充: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連接數設置和獲取的方法
  • PHP連接MySQL數據庫三種實現方法
  • Navicat Premium遠程連接MySQL數據庫的方法
  • 使用IDEA配置Tomcat和連接MySQL數據庫(JDBC)詳細步驟
  • 詳解DBeaver連接MySQL8以上版本以及解決可能遇到的問題
  • 連接docker里面的mysql失敗解決方法
  • 解決navicat遠程連接mysql報錯10038的問題
  • Php連接及讀取和寫入mysql數據庫的常用代碼
  • 遠程連接mysql 授權方法詳解
  • C#連接MySql數據庫的方法
  • MySQL的MaxIdleConns不合理,會變成短連接的原因

標簽:沈陽 鹽城 拉薩 移動 珠海 黔東 沈陽 徐州

巨人網絡通訊聲明:本文標題《淺談Mysql連接數據庫時host和user的匹配規則》,本文關鍵詞  淺談,Mysql,連接,數據庫,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《淺談Mysql連接數據庫時host和user的匹配規則》相關的同類信息!
  • 本頁收集關于淺談Mysql連接數據庫時host和user的匹配規則的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 人獸交高H黄暴辣文| 野人三级在线播放| 桃子直播免费完整版在线观看| 久久久久精品国产亚洲AV澳门| 性一交一乱一交一久怎么形容| 抬腰张开腿撞击h| 深夜一级毛片| 葵司趁夫洗澡公强我了30分钟| 日本黄色电影在线| 好多水流出来了| 福利姬液液酱流白浆| 宝贝帮我拉开拉链它想你了| 高潮?国产?喷水?白网站| bl诱受play多h| 婷婷夜色潮精品综合在线 | 泰国黄色片| 好大好爽快点我要| 国产成人欧美一区二区三区一色天| 亚洲精品老司机| 粗暴强占h| 久久99精品国产91久久久红桃| 扒开老女毛荫荫的黑森林视频| 99久久久久国产| mm131美女大尺度私密照尤果| 《情欲电车2》在线观看| 91人人妻人人澡人人爽人人sex | 亚洲精品无码一区二区三区久久久 | 国产国产伦锂片| 调教男子锁尿肉锁精h| asian艳丽美女pics| 爽死你个放荡小婬妇视频| 男人捅女人视频| 纲手被扒开腿做?同人漫画免费 | 精品国产中文一级毛片在线看| 两性色午夜视频在线观看| 久久久久久精品无码色情| x8x8在线永久免费观看| 美女操p| 国产一区二区免费福利片| 女人被男人艹| 甜蜜惩罚免费观看|