0

0

mysql5.6.12切换binlog二进制日志路径_MySQL

php中文网

php中文网

发布时间:2016-05-27 13:46:21

|

1327人浏览过

|

来源于php中文网

原创

前言:
有一个mysql学生说他们因为binlog产生太大了,需要把日志路径放到另外的磁盘上面去,问我有啥时机的操作方案,share弄了一个mysql的binlog的日志路径切换的例子给他。正好今天有空,就拿mysql5.6.12来做个实例,给大家演示一下。

1,查看binlog地址

[root@mysql5612 ~]# more /usr/local/mysql/my.cnf |grep log-bin
log-bin =/home/data/mysql/binlog/mysql-bin.log
[root@mysql5612 ~]# 

2,验证binlog的正常使用

[root@mysql5612 binlog]# pwd
/home/data/mysql/binlog
[root@mysql5612 binlog]# mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 390217
Server version: 5.6.12-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

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> create table z2 select 2 as a;
ERROR 1046 (3D000): No database selected
mysql> create table test.z2 select 2 as a;
Query OK, 1 row affected (0.04 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> exit
Bye
[root@mysql5612 binlog]# ll
总用量 6240204
-rw-rw----. 1 mysql mysql 1073742187 6月   8 2015 mysql-bin.000048
-rw-rw----. 1 mysql mysql 1073741968 6月   8 2015 mysql-bin.000049
-rw-rw----. 1 mysql mysql 1073742063 6月   8 2015 mysql-bin.000050
-rw-rw----. 1 mysql mysql 1073741957 6月   8 2015 mysql-bin.000051
-rw-rw----. 1 mysql mysql 1073742142 6月   8 2015 mysql-bin.000052
-rw-rw----. 1 mysql mysql 1021194604 12月 10 20:44 mysql-bin.000053
-rw-rw----. 1 mysql mysql        615 6月   8 2015 mysql-bin.index
[root@mysql5612 binlog]# 

看到binlog日志更新了,在20:44时间处,binlog日志mysql-bin.000053有更新记录。然后冲洗mysql服务,看看binlog是否会重新生成:

[root@mysql5612 binlog]# service mysqld56 restart
Shutting down MySQL.................                       [确定]
Starting MySQL.....                                        [确定]
[root@mysql5612 binlog]# 
[root@mysql5612 binlog]# ll
总用量 997276
-rw-rw----. 1 mysql mysql 1021194627 12月 10 20:46 mysql-bin.000053
-rw-rw----. 1 mysql mysql        399 12月 10 20:47 mysql-bin.000054
-rw-rw----. 1 mysql mysql         82 12月 10 20:46 mysql-bin.index
[root@mysql5612 binlog]# 

果然,有新的mysql-bin.000054日志生成了。

原csdn的blog地址:http://blog.csdn.net/mchdba/article/details/50254903,未经过原作者黄杉(mchdba)允许,不得转载


3,去修改binlog日志路径

建立新的binlog日志路径:

[root@mysql5612 binlog]# mkdir -p /home/data/mysql/binlog_new
[root@mysql5612 binlog]# 
[root@mysql5612 binlog]# chown -R mysql.mysql /home/data/mysql/binlog_new
[root@mysql5612 binlog]# 

然后修改my.cnf,设置新的log-bin路径:

[root@mysql5612 binlog]# vim /usr/local/mysql/my.cnf
log-bin =/home/data/mysql/binlog_new/mysql-bin

查看配置文件的binlog路径:

[root@mysql5612 mysql]# more /usr/local/mysql/my.cnf |grep log-bin
log-bin =/home/data/mysql/binlog_new/mysql-bin
[root@mysql5612 mysql]# 

4,重启mysql服务

[root@mysql5612 mysql]# service mysqld56 restart
Shutting down MySQL..                                      [确定]
Starting MySQL.....                                        [确定]
[root@mysql5612 mysql]# 

5,验证新的binlog

查看生成的日志,有新的如下所示:

Catimind
Catimind

专为行业应用打造的AI生产力工具

下载
[root@mysql5612 mysql]# cd /home/data/mysql/binlog_new/
[root@mysql5612 binlog_new]# ll
总用量 12
-rw-rw----. 1 mysql mysql 143 12月 10 21:09 mysql-bin.000001
-rw-rw----. 1 mysql mysql 399 12月 10 21:10 mysql-bin.000002
-rw-rw----. 1 mysql mysql  90 12月 10 21:10 mysql-bin.index
[root@mysql5612 binlog_new]# 

建立新表,录入数据:

[root@mysql5612 binlog_new]# mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.12-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

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> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table z3 select 3 as a;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into z3 select 4;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into z3 select 5;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from z4;
ERROR 1146 (42S02): Table 'test.z4' doesn't exist
mysql> select * from z3;
+---+
| a |
+---+
| 3 |
| 4 |
| 5 |
+---+
3 rows in set (0.00 sec)

mysql> 

再去查看binlog,mysql-bin.000002从399增大到1085,表示有新的二进制日志产生了:

[root@mysql5612 binlog_new]# ll
总用量 12
-rw-rw----. 1 mysql mysql  143 12月 10 21:09 mysql-bin.000001
-rw-rw----. 1 mysql mysql 1085 12月 10 21:11 mysql-bin.000002
-rw-rw----. 1 mysql mysql   90 12月 10 21:10 mysql-bin.index
[root@mysql5612 binlog_new]# 

再使用mysqlbinlog工具去看下产生的新日志是否刚在建立的z3表记录,看到有所有关于test库建立的z3表的操作记录,如下所示:

[root@mysql5612 binlog_new]# /usr/local/mysql/bin/mysqlbinlog --base64-output=DECODE-ROWS -v  mysql-bin.000002
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#151210 21:10:05 server id 72  end_log_pos 120 CRC32 0xa723f142     Start: binlog v 4, server v 5.6.12-log created 151210 21:10:05 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
# at 120
#151210 21:10:07 server id 72  end_log_pos 206 CRC32 0x447f5733     Query   thread_id=1 exec_time=0 error_code=0
SET TIMESTAMP=1449753007/*!*/;
SET @@session.pseudo_thread_id=1/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8mb4 *//*!*/;
SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/;
SET @@session.time_zone='SYSTEM'/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 206
#151210 21:10:07 server id 72  end_log_pos 274 CRC32 0xde0b7250     Table_map: `access_log`.`access_log` mapped to number 70
# at 274
#151210 21:10:07 server id 72  end_log_pos 368 CRC32 0xa03a9659     Write_rows: table id 70 flags: STMT_END_F
### INSERT INTO `access_log`.`access_log`
### SET
###   @1=10534
###   @2=1
###   @3=1449753007
###   @4='[email protected]'
###   @5='[email protected]%'
# at 368
#151210 21:10:07 server id 72  end_log_pos 399 CRC32 0x3ccf3c72     Xid = 3
COMMIT/*!*/;
# at 399
#151210 21:10:58 server id 72  end_log_pos 471 CRC32 0xef9ce950     Query   thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1449753058/*!*/;
BEGIN
/*!*/;
# at 471
#151210 21:10:58 server id 72  end_log_pos 593 CRC32 0x92e79f36     Query   thread_id=2 exec_time=0 error_code=0
use `test`/*!*/;
SET TIMESTAMP=1449753058/*!*/;
CREATE TABLE `z3` (
  `a` int(1) NOT NULL DEFAULT '0'
)
/*!*/;
# at 593
#151210 21:10:58 server id 72  end_log_pos 638 CRC32 0x65f13b58     Table_map: `test`.`z3` mapped to number 107
# at 638
#151210 21:10:58 server id 72  end_log_pos 678 CRC32 0xaa7fb7e1     Write_rows: table id 107 flags: STMT_END_F
### INSERT INTO `test`.`z3`
### SET
###   @1=3
# at 678
#151210 21:10:58 server id 72  end_log_pos 709 CRC32 0x218a319c     Xid = 60
COMMIT/*!*/;
# at 709
#151210 21:11:04 server id 72  end_log_pos 781 CRC32 0x9662b95e     Query   thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1449753064/*!*/;
BEGIN
/*!*/;
# at 781
#151210 21:11:04 server id 72  end_log_pos 826 CRC32 0x46f32822     Table_map: `test`.`z3` mapped to number 107
# at 826
#151210 21:11:04 server id 72  end_log_pos 866 CRC32 0xafb27f1e     Write_rows: table id 107 flags: STMT_END_F
### INSERT INTO `test`.`z3`
### SET
###   @1=4
# at 866
#151210 21:11:04 server id 72  end_log_pos 897 CRC32 0x351c7718     Xid = 63
COMMIT/*!*/;
# at 897
#151210 21:11:10 server id 72  end_log_pos 969 CRC32 0x76931e05     Query   thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1449753070/*!*/;
BEGIN
/*!*/;
# at 969
#151210 21:11:10 server id 72  end_log_pos 1014 CRC32 0xe7e8947b    Table_map: `test`.`z3` mapped to number 107
# at 1014
#151210 21:11:10 server id 72  end_log_pos 1054 CRC32 0xbdafa096    Write_rows: table id 107 flags: STMT_END_F
### INSERT INTO `test`.`z3`
### SET
###   @1=5
# at 1054
#151210 21:11:10 server id 72  end_log_pos 1085 CRC32 0x831695c0    Xid = 64
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@mysql5612 binlog_new]# 

这表明我们的binlog路径切换操作成功完成了。

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
Python 序列化
Python 序列化

本专题整合了python序列化、反序列化相关内容,阅读专题下面的文章了解更多详细内容。

0

2026.02.02

AO3官网入口与中文阅读设置 AO3网页版使用与访问
AO3官网入口与中文阅读设置 AO3网页版使用与访问

本专题围绕 Archive of Our Own(AO3)官网入口展开,系统整理 AO3 最新可用官网地址、网页版访问方式、正确打开链接的方法,并详细讲解 AO3 中文界面设置、阅读语言切换及基础使用流程,帮助用户稳定访问 AO3 官网,高效完成中文阅读与作品浏览。

91

2026.02.02

主流快递单号查询入口 实时物流进度一站式追踪专题
主流快递单号查询入口 实时物流进度一站式追踪专题

本专题聚合极兔快递、京东快递、中通快递、圆通快递、韵达快递等主流物流平台的单号查询与运单追踪内容,重点解决单号查询、手机号查物流、官网入口直达、包裹进度实时追踪等高频问题,帮助用户快速获取最新物流状态,提升查件效率与使用体验。

27

2026.02.02

Golang WebAssembly(WASM)开发入门
Golang WebAssembly(WASM)开发入门

本专题系统讲解 Golang 在 WebAssembly(WASM)开发中的实践方法,涵盖 WASM 基础原理、Go 编译到 WASM 的流程、与 JavaScript 的交互方式、性能与体积优化,以及典型应用场景(如前端计算、跨平台模块)。帮助开发者掌握 Go 在新一代 Web 技术栈中的应用能力。

11

2026.02.02

PHP Swoole 高性能服务开发
PHP Swoole 高性能服务开发

本专题聚焦 PHP Swoole 扩展在高性能服务端开发中的应用,系统讲解协程模型、异步IO、TCP/HTTP/WebSocket服务器、进程与任务管理、常驻内存架构设计。通过实战案例,帮助开发者掌握 使用 PHP 构建高并发、低延迟服务端应用的工程化能力。

5

2026.02.02

Java JNI 与本地代码交互实战
Java JNI 与本地代码交互实战

本专题系统讲解 Java 通过 JNI 调用 C/C++ 本地代码的核心机制,涵盖 JNI 基本原理、数据类型映射、内存管理、异常处理、性能优化策略以及典型应用场景(如高性能计算、底层库封装)。通过实战示例,帮助开发者掌握 Java 与本地代码混合开发的完整流程。

5

2026.02.02

go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

62

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

55

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

27

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
麻省理工大佬Python课程
麻省理工大佬Python课程

共34课时 | 5.2万人学习

【web前端】Node.js快速入门
【web前端】Node.js快速入门

共16课时 | 2万人学习

php-src源码分析探索
php-src源码分析探索

共6课时 | 0.5万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号