bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

MySQL中怎么查看鏈接

今天就跟大家聊聊有關MySQL中怎么查看鏈接,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

創新互聯公司是一家專業提供耿馬企業網站建設,專注與成都網站建設、網站設計、HTML5建站、小程序制作等業務。10年已為耿馬眾多企業、政府機構等服務。創新互聯專業網站建設公司優惠進行中。

1.查看數據庫鏈接

查看數據庫鏈接最常用的語句就是 show processlist 了,這條語句可以查看數據庫中存在的線程狀態。普通用戶只可以查看當前用戶發起的鏈接,具有  PROCESS 全局權限的用戶則可以查看所有用戶的鏈接。

show processlist 結果中的 Info 字段僅顯示每個語句的前 100 個字符,如果需要顯示更多信息,可以使用 show full  processlist 。同樣的,查看 information_schema.processlist 表也可以看到數據庫鏈接狀態信息。

# 普通用戶只能看到當前用戶發起的鏈接 mysql> select user(); +--------------------+ | user()             | +--------------------+ | testuser@localhost | +--------------------+ 1 row in set (0.00 sec)  mysql> show grants; +----------------------------------------------------------------------+ | Grants for testuser@%                                                | +----------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'testuser'@'%'                                 | | GRANT SELECT, INSERT, UPDATE, DELETE ON `testdb`.* TO 'testuser'@'%' | +----------------------------------------------------------------------+ 2 rows in set (0.00 sec)  mysql> show processlist; +--------+----------+-----------+--------+---------+------+----------+------------------+ | Id     | User     | Host      | db     | Command | Time | State    | Info             | +--------+----------+-----------+--------+---------+------+----------+------------------+ | 769386 | testuser | localhost | NULL   | Sleep   |  201 |          | NULL             | | 769390 | testuser | localhost | testdb | Query   |    0 | starting | show processlist | +--------+----------+-----------+--------+---------+------+----------+------------------+ 2 rows in set (0.00 sec)  mysql> select * from information_schema.processlist; +--------+----------+-----------+--------+---------+------+-----------+----------------------------------------------+ | ID     | USER     | HOST      | DB     | COMMAND | TIME | STATE     | INFO                                         | +--------+----------+-----------+--------+---------+------+-----------+----------------------------------------------+ | 769386 | testuser | localhost | NULL   | Sleep   |  210 |           | NULL                                         | | 769390 | testuser | localhost | testdb | Query   |    0 | executing | select * from information_schema.processlist | +--------+----------+-----------+--------+---------+------+-----------+----------------------------------------------+ 2 rows in set (0.00 sec)  # 授予了PROCESS權限后,可以看到所有用戶的鏈接 mysql> grant process on *.* to 'testuser'@'%'; Query OK, 0 rows affected (0.01 sec)  mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)  mysql> show grants; +----------------------------------------------------------------------+ | Grants for testuser@%                                                | +----------------------------------------------------------------------+ | GRANT PROCESS ON *.* TO 'testuser'@'%'                               | | GRANT SELECT, INSERT, UPDATE, DELETE ON `testdb`.* TO 'testuser'@'%' | +----------------------------------------------------------------------+ 2 rows in set (0.00 sec)  mysql> show processlist; +--------+----------+--------------------+--------+---------+------+----------+------------------+ | Id     | User     | Host               | db     | Command | Time | State    | Info             | +--------+----------+--------------------+--------+---------+------+----------+------------------+ | 769347 | root     | localhost          | testdb | Sleep   |   53 |          | NULL             | | 769357 | root     | 192.168.85.0:61709 | NULL   | Sleep   |  521 |          | NULL             | | 769386 | testuser | localhost          | NULL   | Sleep   |  406 |          | NULL             | | 769473 | testuser | localhost          | testdb | Query   |    0 | starting | show processlist | +--------+----------+--------------------+--------+---------+------+----------+------------------+ 4 rows in set (0.00 sec)

通過 show processlist  所得結果,我們可以清晰了解各線程鏈接的詳細信息。具體字段含義還是比較容易理解的,下面具體來解釋下各個字段代表的意思:

  • Id:就是這個鏈接的唯一標識,可通過 kill 命令,加上這個Id值將此鏈接殺掉。

  • User:就是指發起這個鏈接的用戶名。

  • Host:記錄了發送請求的客戶端的 IP 和 端口號,可以定位到是哪個客戶端的哪個進程發送的請求。

  • db:當前執行的命令是在哪一個數據庫上。如果沒有指定數據庫,則該值為 NULL 。

  • Command:是指此刻該線程鏈接正在執行的命令。

  • Time:表示該線程鏈接處于當前狀態的時間。

  • State:線程的狀態,和 Command 對應。

  • Info:記錄的是線程執行的具體語句。

當數據庫鏈接數過多時,篩選有用信息又成了一件麻煩事,比如我們只想查某個用戶或某個狀態的鏈接。這個時候用 show processlist  則會查找出一些我們不需要的信息,此時使用 information_schema.processlist  進行篩選會變得容易許多,下面展示幾個常見篩選需求:

# 只查看某個ID的鏈接信息 select * from information_schema.processlist where id = 705207;  # 篩選出某個用戶的鏈接 select * from information_schema.processlist where user = 'testuser';  # 篩選出所有非空閑的鏈接 select * from information_schema.processlist where command != 'Sleep';  # 篩選出空閑時間在600秒以上的鏈接 select * from information_schema.processlist where command = 'Sleep' and time > 600;  # 篩選出處于某個狀態的鏈接 select * from information_schema.processlist where state = 'Sending data';  # 篩選某個客戶端IP的鏈接 select * from information_schema.processlist where host like '192.168.85.0%';

2.殺掉數據庫鏈接

如果某個數據庫鏈接異常,我們可以通過 kill 語句來殺掉該鏈接,kill 標準語法是:KILL [CONNECTION | QUERY]  processlist_id;

KILL 允許使用可選的 CONNECTION 或 QUERY 修飾符:

  • KILL CONNECTION 與不含修改符的 KILL 一樣,它會終止該 process 相關鏈接。

  • KILL QUERY 終止鏈接當前正在執行的語句,但保持鏈接本身不變。

殺掉鏈接的能力取決于 SUPER 權限:

  • 如果沒有 SUPER 權限,則只能殺掉當前用戶發起的鏈接。

  • 具有 SUPER 權限的用戶,可以殺掉所有鏈接。

遇到突發情況,需要批量殺鏈接時,可以通過拼接 SQL 得到 kill 語句,然后再執行,這樣會方便很多,分享幾個可能用到的殺鏈接的 SQL :

# 殺掉空閑時間在600秒以上的鏈接,拼接得到kill語句 select concat('KILL ',id,';') from information_schema.`processlist`  where command = 'Sleep' and time > 600;  # 殺掉處于某個狀態的鏈接,拼接得到kill語句 select concat('KILL ',id,';') from information_schema.`processlist`  where state = 'Sending data';  select concat('KILL ',id,';') from information_schema.`processlist`  where state = 'Waiting for table metadata lock';  # 殺掉某個用戶發起的鏈接,拼接得到kill語句 select concat('KILL ',id,';') from information_schema.`processlist`   user = 'testuser';

這里提醒下,kill 語句一定要慎用!特別是此鏈接執行的是更新語句或表結構變動語句時,殺掉鏈接可能需要比較長時間的回滾操作。

看完上述內容,你們對MySQL中怎么查看鏈接有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創新互聯行業資訊頻道,感謝大家的支持。

網站標題:MySQL中怎么查看鏈接
網頁地址:http://vcdvsql.cn/article4/ggpjoe.html

成都網站建設公司_創新互聯,為您提供網站排名、品牌網站建設、靜態網站、自適應網站建站公司虛擬主機

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

搜索引擎優化