About MySQL View the number of IP connections and remove this IP connection method

Source: Internet
Author: User
Tags mysql view

Count the total number of MySQL connections for each IP:

Mysql> Select Substring_index (Host, ': ', 1) as IP, COUNT (*) from the information_schema.processlist group by IP;

The status is as follows:

+----------------+----------+| IP |                COUNT (*) |+----------------+----------+|        | 3 | |        10.182.41.191 | 1 | |        10.190.249.204 | 1 | |       10.204.161.60 | 10 | |        localhost | 1 | +----------------+----------+

If ip10.190.249.204 has a process that is connecting to MySQL, we will kill it.

Note: There are other ways to view the total number of MySQL IP connections, such as the MySQL command on Linux to view their status remotely.

Mysql-u root-h127.0.0.1-e "show processlist\g;" | Egrep "Host\:" | Awk-f: ' {print $} ' | Sort | Uniq-c

Or

Mysql-u root-h127.0.0.1--skip-column-names-e "show processlist;" | awk ' {print $} ' |awk-f ': ' ' {print '} ' |sort|uniq–c

Use the following command to see the specific connection status of this IP:

Mysql> Show full processlist;


+--------+-----------------+----------------------+-----------------+-------------+----------+----------------- ------------------------------------------------------+------------------------+| id      | user            | host                  |  db              | command      | Time     | State                                                                     | Info                    |+--------+-----------------+----------------------+-----------------+-------------+-- --------+-----------------------------------------------------------------------+------------------------+|       1 | event_scheduler | localhost             | NULL             | daemon      | 16664843 | waiting  on empty queue                                                  |  Null                   | |       3 | tencentroot     | :34481                | NULL             | sleep       |         5 |                                                                           | NULL                    | |     33 | tencentroot      | :38939                | NULL            |  binlog dump | 16663717 | master has sent all binlog to  slave; waiting for binlog to be updated | null                    | | 460426  | tencentroot     | :45751                | NULL             | Sleep       |         2 |                                                                          |  NULL                    | | 573982 | root             | 10.190.249.204:41661 | db_gfxy_gdb_239 | Sleep        |       24 |                                                                           | NULL                    | | 594340 | root             | 10.204.161.60:40129  |  db_gfxy_gdb_239 | Sleep       |         6 |                                                         &nbsP;                | null                     | | 594341 | root             | 10.204.161.60:40130  | db_gfxy_gdb_239 | Sleep        |        7 |                                                                           | NULL                    | | 594342 | root             | 10.204.161.60:40131  | db_ gfxy_gdb_239 | sleep       |         6 |                                                                           | NULL                    | | 594343 | root             | 10.204.161.60:40132  | db_gfxy_gdb_239 | Sleep        |        6 |                                                                           | NULL                    | | 594344  | root            |  10.204.161.60:40133  | db_gfxy_gdb_239 | sleep        |        6 |                                                                           | NULL                    | | 594345 | root             | 10.204.161.60:40134  | db_gfxy_gdb_239 | sleep        |        6 |                                                                           | NULL                    | | 594346  | root            | 10.204.161.60:40135   | db_gfxy_gdb_239 | Sleep       |         6 |                                                                           | NULL                    | | 594347 | root             | 10.204.161.60:40136  | db_gfxy_gdb_239 | sleep        |        6 |                                                                           | null                    | | 594348 |  root            | 10.204.161.60:40137   | db_gfxy_gdb_239 | Sleep       |         6 |                                                                           | NULL                    | | 594349 | root        &nBsp;    | 10.204.161.60:40138  | db_gfxy_gdb_239 | sleep        |        6 |                                                                           | null                     | | 594402 | root             | 10.182.41.191:55110  | mysql            | query       |        0 | null                                                                      | show full  processlist  |

IP:10.190.249.204 the corresponding ID is 573982, directly kill its ID:

Mysql> kill 573982;

That kills 10.190.249.204 of the connection.


About MySQL View the number of IP connections and remove this IP connection method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.