国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

MySQL 如何連接對(duì)應(yīng)的客戶端進(jìn)程

瀏覽:3日期:2023-10-09 08:03:10

問(wèn)題

對(duì)于一個(gè)給定的 MySQL 連接,我們?nèi)绾尾拍苤浪鼇?lái)自于哪個(gè)客戶端的哪個(gè)進(jìn)程呢?

HandshakeResponse

MySQL-Client 在連接 MySQL-Server 的時(shí)候,不只會(huì)把用戶名密碼發(fā)送到服務(wù)端,還會(huì)把當(dāng)前進(jìn)程id,操作系統(tǒng)名,主機(jī)名等等信息也發(fā)到服務(wù)端。這個(gè)數(shù)據(jù)包就叫 HandshakeResponse 官方有對(duì)其格式進(jìn)行詳細(xì)的說(shuō)明。

我自己改了一個(gè)連接驅(qū)動(dòng),用這個(gè)驅(qū)動(dòng)可以看到連接時(shí)發(fā)送了哪些信息。

2020-05-19 15:31:04,976 - mysql-connector-python.mysql.connector.protocol.MySQLProtocol.make_auth - MainThread - INFO - conn-attrs {’_pid’: ’58471’, ’_platform’: ’x86_64’, ’_source_host’: ’NEEKYJIANG-MB1’, ’_client_name’: ’mysql-connector-python’, ’_client_license’: ’GPL-2.0’, ’_client_version’: ’8.0.20’, ’_os’: ’macOS-10.15.3’}

HandshakeResponse 包的字節(jié)格式如下,要傳輸?shù)臄?shù)據(jù)就在包的最后部分。

4 capability flags, CLIENT_PROTOCOL_41 always set4 max-packet size1 character setstring[23] reserved (all [0])string[NUL] username if capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA {lenenc-int length of auth-responsestring[n] auth-response } else if capabilities & CLIENT_SECURE_CONNECTION {1 length of auth-responsestring[n] auth-response } else {string[NUL] auth-response } if capabilities & CLIENT_CONNECT_WITH_DB {string[NUL] database } if capabilities & CLIENT_PLUGIN_AUTH {string[NUL] auth plugin name } if capabilities & CLIENT_CONNECT_ATTRS {lenenc-int length of all key-valueslenenc-str keylenenc-str value if-more data in ’length of all key-values’, more keys and value pairs }

解決方案

從前面的內(nèi)容我們可以知道 MySQL-Client 確實(shí)向 MySQL-Server 發(fā)送了當(dāng)前的進(jìn)程 id ,這為解決問(wèn)題提供了最基本的可能性。當(dāng)服務(wù)端收到這些信息后雙把它們保存到了 performance_schema.session_connect_attrs。

第一步通過(guò) information_schema.processlist 查詢關(guān)心的連接,它來(lái)自于哪個(gè) IP,和它的 processlist_id 。

mysql> select * from information_schema.processlist;+----+---------+--------------------+--------------------+---------+------+-----------+----------------------------------------------+| ID | USER | HOST| DB | COMMAND | TIME | STATE | INFO |+----+---------+--------------------+--------------------+---------+------+-----------+----------------------------------------------+| 8 | root | 127.0.0.1:57760 | performance_schema | Query | 0 | executing | select * from information_schema.processlist || 7 | appuser | 172.16.192.1:50198 | NULL| Sleep | 2682 | | NULL |+----+---------+--------------------+--------------------+---------+------+-----------+----------------------------------------------+2 rows in set (0.01 sec)

第二步通過(guò) performance_schema.session_connect_attrs 查詢連接的進(jìn)程 ID

mysql> select * from session_connect_attrs where processlist_id = 7; +----------------+-----------------+------------------------+------------------+| PROCESSLIST_ID | ATTR_NAME | ATTR_VALUE | ORDINAL_POSITION |+----------------+-----------------+------------------------+------------------+| 7 | _pid | 58471 |0 || 7 | _platform | x86_64 |1 || 7 | _source_host | NEEKYJIANG-MB1 |2 || 7 | _client_name | mysql-connector-python |3 || 7 | _client_license | GPL-2.0|4 || 7 | _client_version | 8.0.20 |5 || 7 | _os | macOS-10.15.3 |6 |+----------------+-----------------+------------------------+------------------+7 rows in set (0.00 sec)

可以看到 processlist_id = 7 的這個(gè)連接是由 172.16.192.1 的 58471 號(hào)進(jìn)程發(fā)起的。

檢查

我剛才是用的 ipython 連接的數(shù)據(jù)庫(kù),ps 看到的結(jié)果也正是 58471 與查詢出來(lái)的結(jié)果一致。

ps -ef | grep 58471 501 58471 57741 0 3:24下午 ttys001 0:03.67 /Library/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python /Library/Frameworks/Python.framework/Versions/3.8/bin/ipython

以上就是MySQL 如何連接對(duì)應(yīng)的客戶端進(jìn)程的詳細(xì)內(nèi)容,更多關(guān)于MySQL 連接對(duì)應(yīng)的客戶端進(jìn)程的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫(kù)
相關(guān)文章:
主站蜘蛛池模板: 上林县| 四会市| 沁水县| 通化县| 达拉特旗| 建湖县| 乡宁县| 祁阳县| 香河县| 耒阳市| 金堂县| 呼和浩特市| 剑川县| 旅游| 邛崃市| 宜兴市| 辽阳市| 阳泉市| 嘉义县| 夹江县| 依兰县| 浦北县| 宝坻区| 弋阳县| 于田县| 常州市| 静乐县| 正蓝旗| 潜江市| 陆河县| 边坝县| 大关县| 临潭县| 武乡县| 萨嘎县| 定州市| 海盐县| 崇左市| 临江市| 左贡县| 尼勒克县|