午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

--連接數(shù)據(jù)庫時(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)

--那就是說本地登錄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 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.

--查看當(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í) 無問題, 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>

--查看當(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.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>

--查看當(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 來進(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 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');}

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

mysql數(shù)據(jù)庫中user表的host字段,是用來控制用戶訪問數(shù)據(jù)庫“權(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è)參考,也希望大家多多支持好吧啦網(wǎng)。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

標(biāo)簽: MySQL 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 超碰手机在线 | 国产一二区视频 | 人人爽视频 | 色姑娘av | 国产原创视频在线 | 成人av专区 | 国产天堂网| 精品久久在线 | 久久久日韩 | 成人免费公开视频 | 校园春色 亚洲 | 国产成人97精品免费看片 | 日韩精品视频观看 | 国产成人精品免费看视频 | 亚洲综合精品 | 亚洲看片 | 日韩两性视频 | 黄网站在线播放 | 欧洲天堂网 | 欧美特黄视频 | 91福利影院 | 中文字幕第五页 | 大陆av片| 欧美亚一区二区三区 | 日韩在线观看视频网站 | 久操福利 | 久操国产在线 | 91黄色大片| 欧美男人操女人 | 日本一区二区精品 | 欧美激情在线看 | 久综合 | 中文字幕在线观看精品 | 午夜精品区 | 日韩欧美一区二区三区四区 | jizzjizzjizz亚洲女 | 中文字幕在线免费看 | 337p粉嫩大胆噜噜噜亚瑟影院 | 中文字幕精品在线播放 | 欧美顶级毛片在线播放 | 黄视频网站在线观看 |