#!/bin/bash
source /home/mysql/.bashrc
DT=`date '+%Y%m%d_%H%M%S'`
mysql -uroot -p123456 -S /data/3306/mysqldata/mysql.sock -e "select t1.* from information_schema.processlist t1,(select count(1) c from information_schema.processlist where info is not null) t2 where t2.c>=50;" > /home/mysql/processlist_3306.txt
if test -s /home/mysql/processlist_3306.txt; then
mv /home/mysql/processlist_3306.txt /home/mysql/processlist_3306/processlist_3306_${DT}.txt
mysql -uroot -p123456 -S /data/3306/mysqldata/mysql.sock -e "SELECT trx_id, trx_state, trx_started, trx_requested_lock_id, trx_wait_started, trx_weight, trx_mysql_thread_id, trx_query, trx_operation_state, trx_tables_in_use, trx_tables_locked, trx_lock_structs, trx_lock_memory_bytes, trx_rows_locked, trx_rows_modified, trx_concurrency_tickets, trx_isolation_level, trx_unique_checks, trx_foreign_key_checks, trx_last_foreign_key_error, trx_adaptive_hash_latched, trx_adaptive_hash_timeout, trx_is_read_only, trx_autocommit_non_locking FROM information_schema.INNODB_TRX; SELECT requesting_trx_id, requested_lock_id, blocking_trx_id, blocking_lock_id FROM information_schema.INNODB_LOCK_WAITS;SELECT lock_id, lock_trx_id, lock_mode, lock_type, lock_table, lock_index, lock_space, lock_page, lock_rec, lock_data FROM information_schema.INNODB_LOCKS;" > /home/mysql/processlist_3306/innodb_locks_3306_${DT}.txt
else
rm /home/mysql/processlist_3306.txt
fi
find /home/mysql/processlist_3306/* -type f -mtime +10 -exec rm {} \;
#!/bin/bash
source ~/.bashrc
rm -rf /tmp/kill.sql
mysql -uroot -p123456 -S /data/3306/mysqldata/mysql.sock -e "select * into outfile '/tmp/kill.sql' from (select concat('kill ',id,';') from information_schema.processlist where command in ('sleep') ) t; "
mysql -uroot -p123456 -S /data/3306/mysqldata/mysql.sock -f < /tmp/kill.sql
#!/bin/bash
source ~/.bashrc
mysql -uroot -p123456 -S /data/3306/mysqldata/mysql.sock <= current_date()-7;
set global slow_query_log = 'off';
alter table slow_log rename slow_log_drop;
create table slow_log like slow_log_drop;
set global slow_query_log = 'on';
drop table slow_log_drop;
!
4. 定期执行
* * * * * /home/mysql/dbbat/get_processlist.sh
0 6 * * 0 /home/mysql/dbbat/purge_slow_log.sh