Mysql8.0的bin log日志

文章目录

      • 一、 Mysql8.0 的bin log 日志关闭
        • 1.1、查看是否已开启 bin log 日志
        • 1.2、关闭 bin log 日志
        • 1.3、 设置 bin log 日志的时长
          • 1.3.1、第一种设置方式:
          • 1.3.2、第二种设置方式

一、 Mysql8.0 的bin log 日志关闭

Mysql8.0默认开启 binlog 记录功能,如果开启 binlog 日志会增加磁盘I/O等的压力。

//  进入MySQL的数据存放目录下
[root@cloudsino ~]# cd /home/mysqldata/
[root@cloudsino mysqldata]# ll binlog*   // 以下都是 binlog 日志
-rw-r----- 1 mysql mysql 56961557 6月  13 17:25 binlog.000045
-rw-r----- 1 mysql mysql    90378 6月  14 23:05 binlog.000046
-rw-r----- 1 mysql mysql 59466966 6月  16 09:57 binlog.000047
-rw-r----- 1 mysql mysql   751828 6月  19 09:07 binlog.000048
-rw-r----- 1 mysql mysql    12685 6月  19 09:30 binlog.000049
-rw-r----- 1 mysql mysql    22958 6月  19 09:47 binlog.000050
-rw-r----- 1 mysql mysql   883441 6月  20 15:07 binlog.000051
-rw-r----- 1 mysql mysql  2598766 6月  26 08:46 binlog.000052
-rw-r----- 1 mysql mysql  1277318 6月  28 10:01 binlog.000053
-rw-r----- 1 mysql mysql      179 6月  28 10:01 binlog.000054
-rw-r----- 1 mysql mysql  4348744 6月  28 16:01 binlog.000055
-rw-r----- 1 mysql mysql   585765 6月  29 16:50 binlog.000056
-rw-r----- 1 mysql mysql     5011 6月  30 17:14 binlog.000057
-rw-r----- 1 mysql mysql    49526 6月  30 17:50 binlog.000058
-rw-r----- 1 mysql mysql  8440556 7月   3 15:27 binlog.000059
-rw-r----- 1 mysql mysql      534 7月   3 15:30 binlog.000060
-rw-r----- 1 mysql mysql 37368758 7月   6 12:27 binlog.000061
-rw-r----- 1 mysql mysql      179 7月   6 12:27 binlog.000062
-rw-r----- 1 mysql mysql   147165 7月   6 17:32 binlog.000063
-rw-r----- 1 mysql mysql   549347 7月   7 11:35 binlog.000064
-rw-r----- 1 mysql mysql  9371743 7月  12 16:33 binlog.000065
-rw-r----- 1 mysql mysql  2285728 7月  12 19:25 binlog.000066
-rw-r----- 1 mysql mysql      352 7月  12 16:33 binlog.index
[root@cloudsino mysqldata]# 

1.1、查看是否已开启 bin log 日志

[root@cloudsino ~]# mysql  -uroot -pAgan@3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 578
Server version: 8.0.25 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show variables like 'log_bin';  // 查看bin log 日志是否开启。on 表示开启,off表示关闭
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.01 sec)mysql> show master logs;  // 查看现有在用的binlog日志
+---------------+-----------+-----------+
| Log_name      | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000045 |  56961557 | No        |
| binlog.000046 |     90378 | No        |
| binlog.000047 |  59466966 | No        |
| binlog.000048 |    751828 | No        |
| binlog.000049 |     12685 | No        |
| binlog.000050 |     22958 | No        |
| binlog.000051 |    883441 | No        |
| binlog.000052 |   2598766 | No        |
| binlog.000053 |   1277318 | No        |
| binlog.000054 |       179 | No        |
| binlog.000055 |   4348744 | No        |
| binlog.000056 |    585765 | No        |
| binlog.000057 |      5011 | No        |
| binlog.000058 |     49526 | No        |
| binlog.000059 |   8440556 | No        |
| binlog.000060 |       534 | No        |
| binlog.000061 |  37368758 | No        |
| binlog.000062 |       179 | No        |
| binlog.000063 |    147165 | No        |
| binlog.000064 |    549347 | No        |
| binlog.000065 |   9371743 | No        |
| binlog.000066 |   3079494 | No        |
+---------------+-----------+-----------+
22 rows in set (0.00 sec)mysql> reset master;  //  手动清除binlog日志
Query OK, 0 rows affected (0.02 sec)mysql> exit   //  退出

1.2、关闭 bin log 日志

配置文件的方式 my.cnf :
vim /etc/my.cnf
[mysqld]
skip-log-bin  // 添加这一行,重启 mysql 服务后才生效。[root@cloudsino ~]# vim /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password#datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-log-bin   // 添加这一行
...省略N
[root@cloudsino ~]# systemctl restart mysqld  // 重启让其生效
[root@cloudsino ~]#
[root@cloudsino ~]# mysql  -uroot -pAgan@3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 578
Server version: 8.0.25 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show variables like 'log_bin';  // 查看bin log 日志是否开启。on 表示开启,off表示关闭
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | OFF   |
+---------------+-------+
1 row in set (0.01 sec)mysql> 
mysql> show master logs;  // 查看binlog日志报错提醒没有开启binlog
ERROR 1381 (HY000): You are not using binary logging
mysql> 
mysql> exit
Bye
[root@cloudsino ~]# 
[root@cloudsino ~]# ll /home/mysqldata/
总用量 201332
-rw-r----- 1 mysql mysql       56 2月  28 14:15 auto.cnf
-rw------- 1 mysql mysql     1676 2月  28 14:15 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 2月  28 14:15 ca.pem
-rw-r--r-- 1 mysql mysql     1112 2月  28 14:15 client-cert.pem
-rw------- 1 mysql mysql     1680 2月  28 14:15 client-key.pem
-rw-r----- 1 mysql mysql   196608 7月  12 20:04 #ib_16384_0.dblwr
-rw-r----- 1 mysql mysql  8585216 7月   4 14:41 #ib_16384_1.dblwr
-rw-r----- 1 mysql mysql     6344 7月  12 20:02 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 7月  12 20:04 ibdata1
-rw-r----- 1 mysql mysql 50331648 7月  12 20:04 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 7月  12 20:04 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 7月  12 20:02 ibtmp1
drwxr-x--- 2 mysql mysql      187 7月  12 20:02 #innodb_temp
drwxr-x--- 2 mysql mysql      143 2月  28 14:15 mysql
-rw-r----- 1 mysql mysql 37748736 7月  12 20:04 mysql.ibd
drwxr-x--- 2 mysql mysql     8192 2月  28 14:15 performance_schema
-rw------- 1 mysql mysql     1680 2月  28 14:15 private_key.pem
-rw-r--r-- 1 mysql mysql      452 2月  28 14:15 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 2月  28 14:15 server-cert.pem
-rw------- 1 mysql mysql     1680 2月  28 14:15 server-key.pem
drwxr-x--- 2 mysql mysql       28 2月  28 14:15 sys
-rw-r----- 1 mysql mysql 16777216 7月  12 20:04 undo_001
-rw-r----- 1 mysql mysql 16777216 7月  12 20:04 undo_002
[root@cloudsino ~]# 

1.3、 设置 bin log 日志的时长

1.3.1、第一种设置方式:

编辑 /etc/my.cnf 文件,在 [mysqld] 节点中增加如下两行

# 重启 mysql 服务才能生效
log-bin=mysql-bin   #启动日志
max_binlog_size = 200M  # 默认是 1G
expire_logs_days = 7

max_binlog_size:bin log日志每达到设定大小后,会使用新的bin log日志。如mysql-bin.000002达到200M后,创建并使用mysql-bin.000003文件作为日志记录。

expire_logs_days:保留指定日期范围内的bin log历史日志,上示例设置的7天内。


1.3.2、第二种设置方式
# mysql8.0以下版本查看当前数据库日志binlog保存时效 以天为单位,默认0 永不过期,最多只能设置99天
# show variables like 'expire_logs_days';
# set global expire_logs_days=60;# mysql8.0以上版本通过设置全局参数binlog_expire_logs_seconds修改binlog保存时间 以秒为单位;
# 默认2592000 30天;
# 14400   4小时;
# 86400  1天;
# 259200  3天
# show variables like '%binlog_expire_logs_seconds%';
# set global binlog_expire_logs_seconds=259200;[root@cloudsino ~]# mysql -V
mysql  Ver 8.0.25 for Linux on x86_64 (MySQL Community Server - GPL)
[root@cloudsino ~]# mysql  -uroot -pAgan@3306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 308
Server version: 8.0.25 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show variables like '%binlog_expire_logs_seconds%'; // 默认 30 天
+----------------------------+---------+
| Variable_name              | Value   |
+----------------------------+---------+
| binlog_expire_logs_seconds | 2592000 |
+----------------------------+---------+mysql> set global binlog_expire_logs_seconds=259200; // 设置保存3天,重启后失效。
Query OK, 0 rows affected (0.00 sec)mysql> show variables like '%binlog_expire_logs_seconds%';
+----------------------------+--------+
| Variable_name              | Value  |
+----------------------------+--------+
| binlog_expire_logs_seconds | 259200 |
+----------------------------+--------+
1 row in set (0.00 sec)mysql> exit
Bye
[root@cloudsino ~]# 
[root@cloudsino ~]# 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/637.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何配置Git工具

①安装Git:首先确保你已经在计算机上安装了Git。你可以从Git官方网站(https://git-scm.com/)下载适合你操作系统的安装程序,并按照提示进行安装。 ② 配置用户信息:在命令行终端中,使用下面的命令来配置你…

51单片机--DS1302时钟

文章目录 DS1302引脚定义和应用电路内部结构框图寄存器的定义时序定义BCD码DS1302时钟代码 DS1302 DS1302是美国DALLAS公司推出的一款实时时钟电路芯片。它具有高性能和低功耗的特点,可以通过SPI三线接口与CPU进行同步通信。DS1302能够提供秒、分、时、日、星期、月…

【SQL应知应会】表分区(一)• MySQL版

欢迎来到爱书不爱输的程序猿的博客, 本博客致力于知识分享,与更多的人进行学习交流 本文收录于SQL应知应会专栏,本专栏主要用于记录对于数据库的一些学习,有基础也有进阶,有MySQL也有Oracle 分区表 • MySQL版 一、分区表1.非分区表2.分区表2…

Autograd:自动求导

Autograd:自动求导 PyTorch中,所有神经网络的核心是 autograd 包。先简单介绍一下这个包,然后训练我们的第一个的神经网络。 autograd 包为张量上的所有操作提供了自动求导机制。它是一个在运行时定义(define-by-run)的框架&…

利用集合框架实现-超市会员管理系统

借助集合框架来实现超市会员管理系统,实现以下功能: 1.开卡 2.积分累计 3.查询剩余积分 4.积分兑换 5.修改密码 6.退出 -------------------------------------------------------------------------------------------------- 展示&#x…

【信号去噪和分类】基于小波的隐马尔可夫模型统计信号处理(Matlab代码实现)

💥💥💞💞欢迎来到本博客❤️❤️💥💥 🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。 ⛳️座右铭&a…

C语言实现扫雷【经典】

前言   本篇文章要实现的是扫雷游戏,其代码实现与上一篇的三子棋游戏类同,都是在棋盘的基础上,与电脑进行对抗,不同的是,扫雷游戏一开始电脑就已经随机布置好了所有“雷”。 请戳 --->三子棋 扫雷游戏 1. 扫雷游…

【新日语】第17課

练习A 语法练习 一、これはnanakoという電子マネーです。 这是叫做nanako的电子钱包。 解析: これ:“这个”;指示代词 ⇒ これ/あれ/それ「第4課ーP33」。 二、これは留学生が読む雑誌です。 这个是留学生读的杂志…

MySQL每日一练——MySQL多表查询进阶挑战

目录 1、首先创建表 t_dept: t_emp: 2、插入数据 t_dept表: t_tmp表: 3、修改表 4、按条件查找 1、首先创建表 t_dept: CREATE TABLE t_dept (id INT(11) NOT NULL AUTO_INCREMENT,deptName VARCHAR(30) DEFAULT NULL,address VARCHAR(40) DEFAULT NULL,P…

Python结巴中文分词笔记

📚 jieba库基本介绍 🌐 jieba库概述 Jieba是一个流行的中文分词库,它能够将中文文本切分成词语,并对每个词语进行词性标注。中文分词是自然语言处理的重要步骤之一,它对于文本挖掘、信息检索、情感分析等任务具有重要…

Linux服务器丢包故障的解决思路及引申的TCP/IP协议栈理论

Linux服务器丢包故障的解决思路及引申的TCP/IP协议栈理论 我们使用Linux作为服务器操作系统时,为了达到高并发处理能力,充分利用机器性能,经常会进行一些内核参数的调整优化,但不合理的调整常常也会引起意想不到的其他问题&#x…

Elasticsearch原理剖析

一、 Elasticsearch结构 Elasticsearch集群方案由EsMaster、EsClient和EsNode1、EsNode2、EsNode3、EsNode4、EsNode5、EsNode6、EsNode7、EsNode8、EsNode9进程组成,如下图所示,模块说明如表下所示。 说明如表: 名称说明ClientClient使用H…

Android系统启动流程分析

当按下Android系统的开机电源按键时候,硬件会触发引导芯片,执行预定义的代码,然后加载引导程序(BootLoader)到RAM,Bootloader是Android系统起来前第一个程序,主要用来拉起Android系统程序,Android系统被拉起…

C# Linq 详解四

目录 概述 二十、SelectMany 二十一、Aggregate 二十二、DistinctBy 二十三、Reverse 二十四、SequenceEqual 二十五、Zip 二十六、SkipWhile 二十七、TakeWhile C# Linq 详解一 1.Where 2.Select 3.GroupBy 4.First / FirstOrDefault 5.Last / LastOrDefault C# Li…

Prompt本质解密及Evaluation实战与源码解析(一)

第9章 Prompt本质解密及Evaluation实战与源码解析 9.1 Customer Service案例 本节主要谈提示词(Prompt)内部的工作机制,围绕案例、源码、论文三个维度展开。首先,我们可以看一下代码部分,这是对基于大模型应用程序开发的一个评估(Evaluation),这显然是一个至关重要的内…

排序子序列,倒置字符串讲解(图文并茂)

目录 1.排序子序列 2.倒置字符串 1.排序子序列 排序子序列_牛客笔试题_牛客网 (nowcoder.com) 首先题干中提到非递增序列和非递减序列,那么我们就要先弄明白什么是上述2种序列: 非递增序列:a[i] > a[i1] 如:3 2 1 或者 3 3 …

使用docker简单创建一个python容器

/root/docker_python目录结构: . |-- demo | -- main.py -- docker-compose.ymlmain.py内容: # codingutf-8 # -*- coding: utf-8 -*-if __name__ __main__:print("hello world")docker-compose.yml内容: version: "3&q…

注册中心技术Eureka、Nacos

说明:在微服务框架中,各个服务之间都是独立的。理论上来说,各个服务之间是可以直接通信的,但实际上因为服务之间通信需要管理和规划,如请求怎么负载均衡、请求怎么降级处理等等,所以就需要使用一个技术&…

Linux 常用命令

认识 Linux 目录结构 Linux 系统中,磁盘上的文件和目录被组成一棵目录树,每个节点都是目录或文件 Linux 是一个树形目录结构。Linux 上没有盘符概念,不分 C 盘等,根目录 \ 的地位相当与 Java 的 Object ——几个特殊的目录&…

Python+Requests+PyWebIO框架详解,编写测试工具提高团队测试效率

一、背景 老铁们如果是QA,想必也遇到过类似痛点吧: 业务逻辑复杂性决定测试场景复杂性,配置测试场景常常花费大量时间,导致测试效率降低新用户的测试场景,账号可能经常注销,协助debug时需要用userid,每次都得重新抓包。而且测试账号很多,来回切,即使在本地管理userid…