├── LICENSE ├── README.md ├── my2_80.sql └── my2.sql /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 meo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # my2Collector 2 | My2Collector (my2) is a simple, self contained MySQL statistics collector 3 | 4 | ## MySQL Statistics Collector 5 | Most intresting MySQL performance data is available in the GLOBAL_STATUS system table, 6 | but MySQL does not mantain any history of it. 7 | My2Collector (my2) is a simple, self contained MySQL statistics collector. 8 | my2 creates the `my2.status` table that contains the history of performance statistics. 9 | Every 10 minutes my2 automatically executes a Stored Routine to collect data. 10 | 11 | ## Install my2 12 | 13 | To install *my2Collector* execute the following command on Your MySQL database: 14 | 15 | mysql --user=root -pXXX < my2.sql 16 | 17 | For security reasons the creation of the user my2 is commented out: change the password and create the user! 18 | 19 | my2 user creation is in the last 3 lines of the script. 20 | 21 | 22 | #### Database structure 23 | 24 | `my2.status` table has columns similar to the MySQL GLOBAL_STATUS system table: 25 | * variable_name 26 | * variable_value 27 | 28 | my2.status adds a third column `timest` with the timestamp 29 | 30 | 31 | #### Available statistics 32 | 33 | `my2.status` table collects several performance statistics: 34 | * All numeric GLOBAL_STATUS variables 35 | * All statement execution counters ("statement/sql/%" from events_statements_summary_global_by_event_name) 36 | * Some PROCESSLIST information (eg. USER, HOST, COMMAND, STATE) 37 | * Some summary statistic (eg. sum_timer_wait from events_statements_summary_global_by_event_name) 38 | * Some GLOBAL_VARIABLE variables 39 | * Delta values for most used counters using `my2.current` stage table 40 | * Database size (collected daily and not every 10 minutes) 41 | * And other useful stats... 42 | 43 | 44 | ### Statistics usage 45 | 46 | SELECT variable_value+0 as value, timest as time_sec 47 | FROM my2.status 48 | WHERE variable_name='THREADS_CONNECTED' 49 | ORDER BY timest ASC; 50 | 51 | 52 | ## Version support 53 | 54 | my2 can connect to any version of MySQL, MariaDB, Percona, or other forks but... 55 | with old MySQL releases many statistics not available. 56 | my2 uses a Scheduled Job which is available since MySQL 5.1 (2008). 57 | PROCESSLIST table is available since 5.1.7 while GLOBAL_STATUS is available since 5.1.12. 58 | The PERFORMANCE_SCHEMA was introduced in 5.5 version and greatly enhanched in 5.6 version. 59 | There are many little differences between different MySQL versions: My2 is aware of them 60 | and tries to collect all the information available. For MySQL 8.0 a different script is provided. 61 | my2 gives its best with MySQL 5.7, MySQL 8.0 and MariaDB 10.x with performance schema enabled. 62 | -------------------------------------------------------------------------------- /my2_80.sql: -------------------------------------------------------------------------------- 1 | -- by mail@meo.bogliolo.name 2 | -- My2_80 Collector 3 | -- 0.0.1 2013-02-14 First version for MySQL 5.6 4 | -- 0.0.6 2017-04-01 DBCPU as SUM_TIMER_WAIT from events_statements_summary_global_by_event_name 5 | -- 0.0.7 2017-11-01 bug fixed (0 as first value for delta), MariaDB 10.2 support, new custom statistics 6 | -- 0.0.7a 2018-02-18 substr(EVENT_NAME,15) --> substr(EVENT_NAME,15,60) 7 | -- 0.0.8 2018-04-01 MySQL v.8.0 support 8 | -- 0.0.9a 2018-08-15 Delta statistics (useful for Grafana and others), (a) got some useful global_variable 9 | -- 0.0.10 2018-10-31 Replication Lag (also with multi-threaded slaves) 10 | -- 0.0.11 2019-05-05 MySQL v.8 only 11 | -- 0.0.12 2021-06-22 grants on performance_schema (needed for 8.x) 12 | 13 | -- Create Database, Tables, Stored Routines and Jobs for My2 dashboard 14 | create database IF NOT EXISTS my2; 15 | use my2; 16 | CREATE TABLE IF NOT EXISTS status ( 17 | VARIABLE_NAME varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '', 18 | VARIABLE_VALUE varchar(1024) CHARACTER SET utf8 DEFAULT NULL, 19 | TIMEST timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 20 | ) ENGINE=InnoDB; 21 | 22 | CREATE TABLE IF NOT EXISTS current ( 23 | VARIABLE_NAME varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '', 24 | VARIABLE_VALUE varchar(1024) CHARACTER SET utf8 DEFAULT NULL 25 | ) ENGINE=InnoDB; 26 | 27 | ALTER TABLE status 28 | ADD unique KEY idx01 (VARIABLE_NAME,timest); 29 | -- delete from my2.status where VARIABLE_NAME like 'PROCESSES_HOSTS.%'; 30 | -- update my2.status set variable_value=0, timest=timest where VARIABLE_NAME like '%-d' and variable_value<0; 31 | ALTER TABLE current 32 | ADD unique KEY idx02 (VARIABLE_NAME); 33 | 34 | DROP PROCEDURE IF EXISTS collect_stats; 35 | DELIMITER // ; 36 | CREATE PROCEDURE collect_stats() 37 | BEGIN 38 | DECLARE a datetime; 39 | DECLARE v varchar(10); 40 | set sql_log_bin = 0; 41 | set a=now(); 42 | select substr(version(),1,3) into v; 43 | 44 | insert into my2.status(variable_name,variable_value,timest) 45 | select upper(variable_name),variable_value, a 46 | from performance_schema.global_status 47 | where variable_value REGEXP '^-*[[:digit:]]+(\.[[:digit:]]+)?$' 48 | and variable_name not like 'Performance_schema_%' 49 | and variable_name not like 'SSL_%'; 50 | insert into my2.status(variable_name,variable_value,timest) 51 | SELECT 'REPLICATION_MAX_WORKER_TIME', coalesce(max(PROCESSLIST_TIME), 0.1), a 52 | FROM performance_schema.threads 53 | WHERE (NAME = 'thread/sql/slave_worker' 54 | AND (PROCESSLIST_STATE IS NULL 55 | OR PROCESSLIST_STATE != 'Waiting for an event from Coordinator')) 56 | OR NAME = 'thread/sql/slave_sql'; 57 | insert into my2.status(variable_name,variable_value,timest) 58 | select concat('PROCESSES.',user),count(*),a 59 | from information_schema.processlist 60 | group by user; 61 | insert into my2.status(variable_name,variable_value,timest) 62 | select concat('PROCESSES_HOSTS.',SUBSTRING_INDEX(host,':',1)),count(*),a 63 | from information_schema.processlist 64 | group by concat('PROCESSES_HOSTS.',SUBSTRING_INDEX(host,':',1)); 65 | insert into my2.status(variable_name,variable_value,timest) 66 | select concat('PROCESSES_COMMAND.',command),count(*),a 67 | from information_schema.processlist 68 | group by concat('PROCESSES_COMMAND.',command); 69 | insert into my2.status(variable_name,variable_value,timest) 70 | select substr(concat('PROCESSES_STATE.',state),1,64),count(*),a 71 | from information_schema.processlist 72 | group by substr(concat('PROCESSES_STATE.',state),1,64); 73 | insert into my2.status(variable_name,variable_value,timest) 74 | SELECT 'SUM_TIMER_WAIT', sum(sum_timer_wait*1.0), a 75 | FROM performance_schema.events_statements_summary_global_by_event_name; 76 | 77 | -- Delta values 78 | insert into my2.status(variable_name,variable_value,timest) 79 | select concat(upper(s.variable_name),'-d'), greatest(s.variable_value-c.variable_value,0), a 80 | from performance_schema.global_status s, my2.current c 81 | where s.variable_name=c.variable_name; 82 | insert into my2.status(variable_name,variable_value,timest) 83 | SELECT concat('COM_',upper(substr(s.EVENT_NAME,15,58)), '-d'), greatest(s.COUNT_STAR-c.variable_value,0), a 84 | FROM performance_schema.events_statements_summary_global_by_event_name s, my2.current c 85 | WHERE s.EVENT_NAME LIKE 'statement/sql/%' 86 | AND s.EVENT_NAME = c.variable_name; 87 | insert into my2.status(variable_name,variable_value,timest) 88 | SELECT 'SUM_TIMER_WAIT-d', sum(sum_timer_wait*1.0)-c.variable_value, a 89 | FROM performance_schema.events_statements_summary_global_by_event_name, my2.current c 90 | WHERE c.variable_name='SUM_TIMER_WAIT'; 91 | insert into my2.status(variable_name, variable_value, timest) 92 | select 'REPLICATION_CONNECTION_STATUS',if(SERVICE_STATE='ON', 1, 0),a 93 | from performance_schema.replication_connection_status; 94 | insert into my2.status(variable_name, variable_value, timest) 95 | select 'REPLICATION_APPLIER_STATUS',if(SERVICE_STATE='ON', 1, 0),a 96 | from performance_schema.replication_applier_status; 97 | delete from my2.current; 98 | insert into my2.current(variable_name,variable_value) 99 | select upper(variable_name),variable_value+0 100 | from performance_schema.global_status 101 | where variable_value REGEXP '^-*[[:digit:]]+(\.[[:digit:]]+)?$' 102 | and variable_name not like 'Performance_schema_%' 103 | and variable_name not like 'SSL_%'; 104 | insert into my2.current(variable_name,variable_value) 105 | SELECT substr(EVENT_NAME,1,40), COUNT_STAR 106 | FROM performance_schema.events_statements_summary_global_by_event_name 107 | WHERE EVENT_NAME LIKE 'statement/sql/%'; 108 | insert into my2.current(variable_name,variable_value) 109 | SELECT 'SUM_TIMER_WAIT', sum(sum_timer_wait*1.0) 110 | FROM performance_schema.events_statements_summary_global_by_event_name; 111 | 112 | insert into my2.current(variable_name,variable_value) 113 | select concat('PROCESSES_COMMAND.',command),count(*) 114 | from information_schema.processlist 115 | group by concat('PROCESSES_COMMAND.',command); 116 | insert into my2.current(variable_name,variable_value) 117 | select upper(variable_name),variable_value 118 | from performance_schema.global_variables 119 | where variable_name in ('max_connections', 'innodb_buffer_pool_size', 'query_cache_size', 120 | 'innodb_log_buffer_size', 'key_buffer_size', 'table_open_cache'); 121 | set sql_log_bin = 1; 122 | END // 123 | DELIMITER ; // 124 | 125 | -- Collect daily statistics on space usage and delete old statistics (older than 62 days, 1 year for DB size) 126 | DROP PROCEDURE IF EXISTS collect_daily_stats; 127 | DELIMITER // ; 128 | CREATE PROCEDURE collect_daily_stats() 129 | BEGIN 130 | DECLARE a datetime; 131 | set sql_log_bin = 0; 132 | set a=now(); 133 | insert into my2.status(variable_name,variable_value,timest) 134 | select concat('SIZEDB.',table_schema), sum(data_length+index_length), a 135 | from information_schema.tables group by table_schema; 136 | insert into my2.status(variable_name,variable_value,timest) 137 | select 'SIZEDB.TOTAL', sum(data_length+index_length), a 138 | from information_schema.tables; 139 | delete from my2.status where timest < date_sub(now(), INTERVAL 62 DAY) and variable_name <>'SIZEDB.TOTAL'; 140 | delete from my2.status where timest < date_sub(now(), INTERVAL 365 DAY); 141 | set sql_log_bin = 1; 142 | END // 143 | DELIMITER ; // 144 | 145 | -- The event scheduler must also be activated in the my.cnf (event_scheduler=1) 146 | set global event_scheduler=1; 147 | 148 | set sql_log_bin = 0; 149 | DROP EVENT IF EXISTS collect_stats; 150 | CREATE EVENT collect_stats 151 | ON SCHEDULE EVERY 10 Minute 152 | DO call collect_stats(); 153 | DROP EVENT IF EXISTS collect_daily_stats; 154 | CREATE EVENT collect_daily_stats 155 | ON SCHEDULE EVERY 1 DAY 156 | DO call collect_daily_stats(); 157 | set sql_log_bin = 1; 158 | 159 | -- Use a specific user (suggested) 160 | -- create user my2@'%' identified by 'P1e@seCh@ngeMe'; 161 | -- grant all on my2.* to my2@'%'; 162 | -- grant select on performance_schema.* to my2@'%'; 163 | -------------------------------------------------------------------------------- /my2.sql: -------------------------------------------------------------------------------- 1 | -- by mail@meo.bogliolo.name 2 | -- My2 Collector 3 | -- 0.0.1 2013-02-14 First version for MySQL 5.6 4 | -- 0.0.6 2017-04-01 DBCPU as SUM_TIMER_WAIT from events_statements_summary_global_by_event_name 5 | -- 0.0.7 2017-11-01 bug fixed (0 as first value for delta), MariaDB 10.2 support, new custom statistics 6 | -- 0.0.7a 2018-02-18 substr(EVENT_NAME,15) --> substr(EVENT_NAME,15,60) 7 | -- 0.0.8 2018-04-01 MySQL v.8.0 support 8 | -- 0.0.9a 2018-08-15 Delta statistics (useful for Grafana), (a) got some useful global_variable 9 | -- 0.0.10 2018-10-31 Replication Lag (with multi-threaded slaves), (a) changed a variable name 10 | -- 0.0.11 2019-05-05 Small changes (uppercase variables, enable events) 11 | -- 0.0.12 2020-01-01 Host column, MariaDB 10.x better support 12 | 13 | -- Create Database, Tables, Stored Routines and Jobs for My2 dashboard 14 | create database IF NOT EXISTS my2; 15 | use my2; 16 | CREATE TABLE IF NOT EXISTS status ( 17 | VARIABLE_NAME varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '', 18 | VARIABLE_VALUE varchar(1024) CHARACTER SET utf8 DEFAULT NULL, 19 | HOST varchar(128) CHARACTER SET utf8 DEFAULT 'MyHost', -- concat(@@hostname, ':', @@port), 20 | TIMEST timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 21 | ) ENGINE=InnoDB; 22 | 23 | CREATE TABLE IF NOT EXISTS current ( 24 | VARIABLE_NAME varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '', 25 | VARIABLE_VALUE varchar(1024) CHARACTER SET utf8 DEFAULT NULL 26 | ) ENGINE=InnoDB; 27 | 28 | ALTER TABLE status 29 | ADD unique KEY idx01 (VARIABLE_NAME,timest,host); 30 | -- delete from my2.status where VARIABLE_NAME like 'PROCESSES_HOSTS.%'; 31 | -- update my2.status set variable_value=0, timest=timest where VARIABLE_NAME like '%-d' and variable_value<0; 32 | ALTER TABLE current 33 | ADD unique KEY idx02 (VARIABLE_NAME); 34 | 35 | DROP PROCEDURE IF EXISTS collect_stats; 36 | DELIMITER // ; 37 | CREATE PROCEDURE collect_stats() 38 | BEGIN 39 | DECLARE a datetime; 40 | DECLARE v varchar(10); 41 | -- set sql_log_bin = 0; 42 | set a=now(); 43 | select substr(version(),1,3) into v; 44 | 45 | if v='5.7' OR v='8.0' then 46 | insert into my2.status(variable_name,variable_value,timest) 47 | select upper(variable_name),variable_value, a 48 | from performance_schema.global_status 49 | where variable_value REGEXP '^-*[[:digit:]]+(\.[[:digit:]]+)?$' 50 | and variable_name not like 'Performance_schema_%' 51 | and variable_name not like 'SSL_%'; 52 | insert into my2.status(variable_name,variable_value,timest) 53 | SELECT 'REPLICATION_MAX_WORKER_TIME', coalesce(max(PROCESSLIST_TIME), 0.1), a 54 | FROM performance_schema.threads 55 | WHERE (NAME = 'thread/sql/slave_worker' 56 | AND (PROCESSLIST_STATE IS NULL 57 | OR PROCESSLIST_STATE != 'Waiting for an event from Coordinator')) 58 | OR NAME = 'thread/sql/slave_sql'; 59 | -- *** Comment the following 4 lines with 8.0 *** 60 | else 61 | insert into my2.status(variable_name,variable_value,timest) 62 | select variable_name,variable_value,a 63 | from information_schema.global_status; 64 | end if; 65 | insert into my2.status(variable_name,variable_value,timest) 66 | select concat('PROCESSES.',user),count(*),a 67 | from information_schema.processlist 68 | group by user; 69 | insert into my2.status(variable_name,variable_value,timest) 70 | select concat('PROCESSES_HOSTS.',SUBSTRING_INDEX(host,':',1)),count(*),a 71 | from information_schema.processlist 72 | group by concat('PROCESSES_HOSTS.',SUBSTRING_INDEX(host,':',1)); 73 | insert into my2.status(variable_name,variable_value,timest) 74 | select concat('PROCESSES_COMMAND.',command),count(*),a 75 | from information_schema.processlist 76 | group by concat('PROCESSES_COMMAND.',command); 77 | insert into my2.status(variable_name,variable_value,timest) 78 | select substr(concat('PROCESSES_STATE.',state),1,64),count(*),a 79 | from information_schema.processlist 80 | group by substr(concat('PROCESSES_STATE.',state),1,64); 81 | if v='5.6' OR v='5.7' OR v='8.0' OR v='10.' then 82 | insert into my2.status(variable_name,variable_value,timest) 83 | SELECT 'SUM_TIMER_WAIT', sum(sum_timer_wait*1.0), a 84 | FROM performance_schema.events_statements_summary_global_by_event_name; 85 | end if; 86 | 87 | -- Delta values 88 | if v='5.7' OR v='8.0' then 89 | insert into my2.status(variable_name,variable_value,timest) 90 | select concat(upper(s.variable_name),'-d'), greatest(s.variable_value-c.variable_value,0), a 91 | from performance_schema.global_status s, my2.current c 92 | where s.variable_name=c.variable_name; 93 | insert into my2.status(variable_name,variable_value,timest) 94 | SELECT concat('COM_',upper(substr(s.EVENT_NAME,15,58)), '-d'), greatest(s.COUNT_STAR-c.variable_value,0), a 95 | FROM performance_schema.events_statements_summary_global_by_event_name s, my2.current c 96 | WHERE s.EVENT_NAME LIKE 'statement/sql/%' 97 | AND s.EVENT_NAME = c.variable_name; 98 | insert into my2.status(variable_name,variable_value,timest) 99 | SELECT 'SUM_TIMER_WAIT-d', sum(sum_timer_wait*1.0)-c.variable_value, a 100 | FROM performance_schema.events_statements_summary_global_by_event_name, my2.current c 101 | WHERE c.variable_name='SUM_TIMER_WAIT'; 102 | insert into my2.status(variable_name, variable_value, timest) 103 | select 'REPLICATION_CONNECTION_STATUS', if(SERVICE_STATE='ON', 1, 0),a 104 | from performance_schema.replication_connection_status; 105 | insert into my2.status(variable_name, variable_value, timest) 106 | select 'REPLICATION_APPLIER_STATUS', if(SERVICE_STATE='ON', 1, 0),a 107 | from performance_schema.replication_applier_status; 108 | 109 | delete from my2.current; 110 | insert into my2.current(variable_name,variable_value) 111 | select upper(variable_name),variable_value+0 112 | from performance_schema.global_status 113 | where variable_value REGEXP '^-*[[:digit:]]+(\.[[:digit:]]+)?$' 114 | and variable_name not like 'Performance_schema_%' 115 | and variable_name not like 'SSL_%'; 116 | insert into my2.current(variable_name,variable_value) 117 | SELECT substr(EVENT_NAME,1,40), COUNT_STAR 118 | FROM performance_schema.events_statements_summary_global_by_event_name 119 | WHERE EVENT_NAME LIKE 'statement/sql/%'; 120 | insert into my2.current(variable_name,variable_value) 121 | SELECT 'SUM_TIMER_WAIT', sum(sum_timer_wait*1.0) 122 | FROM performance_schema.events_statements_summary_global_by_event_name; 123 | 124 | insert into my2.current(variable_name,variable_value) 125 | select concat('PROCESSES_COMMAND.',command),count(*) 126 | from information_schema.processlist 127 | group by concat('PROCESSES_COMMAND.',command); 128 | insert into my2.current(variable_name,variable_value) 129 | select upper(variable_name),variable_value 130 | from performance_schema.global_variables 131 | where variable_name in ('max_connections', 'innodb_buffer_pool_size', 'query_cache_size', 132 | 'innodb_log_buffer_size', 'key_buffer_size', 'table_open_cache'); 133 | else 134 | insert into my2.status(variable_name,variable_value,timest) 135 | select concat(upper(s.variable_name),'-d'), greatest(s.variable_value-c.variable_value,0), a 136 | from information_schema.global_status s, my2.current c 137 | where s.variable_name=c.variable_name; 138 | delete from my2.current; 139 | insert into my2.current(variable_name,variable_value) 140 | select upper(variable_name),variable_value+0 141 | from information_schema.global_status 142 | where variable_value REGEXP '^-*[[:digit:]]+(\.[[:digit:]]+)?$' 143 | and variable_name not like 'Performance_schema_%' 144 | and variable_name not like 'SSL_%'; 145 | insert into my2.current(variable_name,variable_value) 146 | select upper(variable_name),variable_value 147 | from information_schema.global_variables 148 | where variable_name in ('max_connections', 'innodb_buffer_pool_size', 'query_cache_size', 149 | 'innodb_log_buffer_size', 'key_buffer_size', 'table_open_cache'); 150 | end if; 151 | 152 | -- set sql_log_bin = 1; 153 | END // 154 | DELIMITER ; // 155 | 156 | -- Collect daily statistics on space usage and delete old statistics (older than 62 days, 1 year for DB size) 157 | DROP PROCEDURE IF EXISTS collect_daily_stats; 158 | DELIMITER // ; 159 | CREATE PROCEDURE collect_daily_stats() 160 | BEGIN 161 | DECLARE a datetime; 162 | -- set sql_log_bin = 0; 163 | set a=now(); 164 | insert into my2.status(variable_name,variable_value,timest) 165 | select concat('SIZEDB.',table_schema), sum(data_length+index_length), a 166 | from information_schema.tables group by table_schema; 167 | insert into my2.status(variable_name,variable_value,timest) 168 | select 'SIZEDB.TOTAL', sum(data_length+index_length), a 169 | from information_schema.tables; 170 | delete from my2.status where timest < date_sub(now(), INTERVAL 62 DAY) and variable_name <>'SIZEDB.TOTAL'; 171 | delete from my2.status where timest < date_sub(now(), INTERVAL 365 DAY); 172 | -- set sql_log_bin = 1; 173 | END // 174 | DELIMITER ; // 175 | 176 | -- The event scheduler must also be activated in the my.cnf (event_scheduler=1) 177 | set global event_scheduler=1; 178 | 179 | -- set sql_log_bin = 0; 180 | DROP EVENT IF EXISTS collect_stats; 181 | CREATE EVENT collect_stats 182 | ON SCHEDULE EVERY 10 Minute 183 | DO call collect_stats(); 184 | DROP EVENT IF EXISTS collect_daily_stats; 185 | CREATE EVENT collect_daily_stats 186 | ON SCHEDULE EVERY 1 DAY 187 | DO call collect_daily_stats(); 188 | 189 | ALTER EVENT collect_stats ENABLE; 190 | ALTER EVENT collect_daily_stats ENABLE; 191 | -- set sql_log_bin = 1; 192 | 193 | -- Use a specific user (suggested) 194 | -- create user my2@'%' identified by 'P1e@seCh@ngeMe'; 195 | -- grant all on my2.* to my2@'%'; 196 | --------------------------------------------------------------------------------