mysql数据库访问慢排查,通过binlog恢复删除数据
mysql数据库访问慢排查
show processlist;
慢查询相关参数
show variables like ‘%query%’;
long_query_time 设置慢查询记录的阈值,单位秒
+———————————-+——-+
| Variable_name | Value |
+———————————-+——-+
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| long_query_time | 10.000000 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 0 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| slow_query_log | OFF |
| slow_query_log_file | /var/log/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_format | DATETIME |
| slow_query_log_threshold_queries | 100 |
| slow_query_log_threshold_seconds | 10 |
| sql_log_bin_trust_function_creators | OFF |
+———————————-+——-+
query_cache_size:查询缓存的大小。如果设置为0,则禁用查询缓存。
query_cache_type:查询缓存的类型,可以是OFF(禁用)、ON(启用,但仅缓存SELECT语句)或DEMAND(仅缓存明确指定了SQL_CACHE的SELECT语句)。
long_query_time:慢查询日志的阈值,单位是秒。任何执行时间超过此值的查询都会被记录到慢查询日志中(如果慢查询日志被启用)。
slow_query_log:是否启用慢查询日志。
slow_query_log_file:慢查询日志文件的路径。
query_alloc_block_size 和 query_prealloc_size:与查询执行时内存分配相关的参数,这些参数影响查询的性能,但通常不需要手动调整。
set global show_query_log = ON;
select * from user where id =’1′ and sleep sleep(60);
show processlist;
mysqldumpslow
通过binlog恢复删除数据
show variables like ‘%log_bin%’;
SHOW MASTER STATUS;
create table text (id int(3)not null,name varchar(8) not null);
insert into text values (1, ‘Allen’);
insert into text values (2, ‘Bob’);
insert into text values (3, ‘Tom’);
mysql> select * from text;
CREATE TABLE text1 (
-> id INT NOT NULL,
-> na VARCHAR(8) NOT NULL,
-> PRIMARY KEY (id)
-> );
delete from text where 1=1;
WHERE 1=1 是一个始终为真的条件,因为它比较的是数字 1 是否等于 1,这显然是真的。
mysql> select * from text;
Empty set (0.00 sec)
mysqlbinlog /www/server/data/mysql-bin.000012 > /tmp/binlog1.sql
view /tmp/binlog1.sql
at 1285
240727 22:26:54 server id 1 end_log_pos 1441 CRC32 0xe19755ed Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1722090414/!/;
CREATE TABLE text1 (
id INT NOT NULL,
na VARCHAR(8) NOT NULL,
PRIMARY KEY (id)
at 1441
240727 22:33:05 server id 1 end_log_pos 1506 CRC32 0xddfb02d3 Ignorable
Ignorable event type 34 (MySQL Anonymous_Gtid)
at 1506
240727 22:33:05 server id 1 end_log_pos 1587 CRC32 0x45dfb8ab Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1722090785/!/;
BEGIN
/!/;
at 1587
240727 22:33:05 server id 1 end_log_pos 1689 CRC32 0x9303cb4a Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1722090785/!/;
delete from text where 1=1
/!/;
at 1689
240727 22:33:05 server id 1 end_log_pos 1720 CRC32 0xeb1d9de0 Xid = 17
COMMIT/!/;
DELIMITER ;
End of log file
ROLLBACK /* added by mysqlbinlog /; /!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
通过位置恢复,误操作之前的点
:q
[root@iZbp1cr1sgiqi6r6qlygx9Z ~]# mysqlbinlog –stop-position=1220 /www/server/data/mysql-bin.000012 | mysql -uroot -p
Enter password:
FLUSH LOGS;
SHOW MASTER STATUS;
![图片[1]-mysql数据库访问慢排查,通过binlog恢复删除数据-晴天生活分享日志](https://osaka2.cn/wp-content/uploads/2024/07/16411030F2FBB762D45482B6ED11E368.jpg)
感谢您的来访,获取更多精彩文章请收藏本站。
1. 资源都是经过站长或作者收集测试修改后发布分享。转载请在文内以超链形式注明出处,谢谢合作!
2. 本站除原创内容,其余所有内容均收集自互联网,仅限用于学习和研究目的,本站不对其内容的合法性承担任何责任。如有版权内容,请通知我们或作者删除,其版权均归原作者所有,本站虽力求保存原有版权信息,但因众多资源经多次转载,已无法确定其真实来源,或已将原有信息丢失,所以敬请原作者谅解!
3. 本站用户所发布的一切资源内容不代表本站立场,并不代表本站赞同其观点和对其真实性负责,若您对本站所载资源作品版权归属存有异议,请留言附说明联系邮箱,我们将在第一时间予以处理 ,同时向您表示歉意!为尊重作者版权,请购买原版作品,支持您喜欢的作者,谢谢!
4. 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客如有发现请立即向站长举报;本站资源文件大多存储在云盘,如发现链接或图片失效,请联系作者或站长及时更新。

测试-晴天生活分享日志">
彩虹易支付使用教程-晴天生活分享日志">



暂无评论内容