MySQL 5.6中备份及还原performance_schema配置

本文介绍如何使用setup.txt脚本备份并还原MySQL performance_schema的配置,包括更新instruments和consumers表的启用状态,确保数据库性能监控的正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、setup.txt文件,用于备份performance_schema的配置。该脚本生成还原performance_schema中的setup表的SQL语句。

-- 备份setup_instruments
select concat('update performance_schema.setup_instruments set enabled=''',enabled,''' where name=''',name,''';')
from performance_schema.setup_instruments where enabled='NO';

-- 备份setup_consumers
select concat('update performance_schema.setup_consumers set enabled=''',enabled,''' where name=''',name,''';')
from performance_schema.setup_consumers where enabled='NO';

-- commit
select 'commit;';



二、执行setup.txt文件,备份performance_schema的配置。
mysql -h localhost -P 3306 -u root -pmysql -D test -s < d:\atmp\backup_perf_setup.sql > d:\ATMP\restore_perf_setup.sql


三、开启所有的setup配置进行监控。
update performance_schema.setup_instruments set enabled='YES' where enabled='NO';
update performance_schema.setup_consumers set enabled='YES' where enabled='NO';
commit;


四、监控完成后,还原performance_schema的配置。
D:\software\mysql\mysql-5.6.14-win32\bin>mysql -h localhost -P 3306 -u root -pmysql -D test -s < d:\ATMP\restore_perf_setup.sql


五、清空performance_schema的监控表的记录。
SELECT CONCAT('truncate table performance_schema.',table_name,';')
FROM information_schema.TABLES
WHERE table_schema='performance_schema'
AND table_name NOT LIKE 'setup%'
AND table_name NOT LIKE '%instances'
AND table_name NOT LIKE '%attrs'
AND table_name NOT IN ('performance_timers', 'threads');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值