· 8 years ago · Nov 28, 2017, 08:58 PM
1DROP TABLE IF EXISTS mysql.`max_used_connections`;
2
3CREATE TABLE mysql.`max_used_connections` (
4 `USER` char(16) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
5 `HOST` char(60) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
6 `MAX_USED_CONNECTIONS` bigint(20) NOT NULL,
7 PRIMARY KEY (`USER`, `HOST`) USING HASH
8) ENGINE=MEMORY DEFAULT CHARSET=utf8
9;
10
11DROP EVENT IF EXISTS mysql.gather_max_used_connections;
12
13-- event_scheduler = on
14CREATE DEFINER=root@localhost EVENT mysql.gather_max_used_connections
15ON SCHEDULE EVERY 10 SECOND
16DO
17INSERT INTO mysql.max_used_connections
18SELECT user, host, current_connections
19 FROM performance_schema.accounts
20 WHERE user IS NOT NULL
21 AND host IS NOT NULL
22 ON DUPLICATE KEY
23UPDATE max_used_connections = IF(current_connections > max_used_connections, current_connections, max_used_connections)
24;