찾다
데이터 베이스MySQL 튜토리얼mysql5.6.12切换binlog二进制日志路径_MySQL

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

1,查看binlog地址

<code class=" hljs mel">[root@mysql5612 ~]# more /usr/local/mysql/my.cnf |grep log-bin
log-bin =/home/data/mysql/binlog/mysql-bin.log
[root@mysql5612 ~]# 

2,验证binlog的正常使用

<code class=" hljs applescript">[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是否会重新生成:

<code class=" hljs css">[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日志路径:

<code class=" hljs ruby">[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路径:

<code class=" hljs ruby">[root@mysql5612 binlog]# vim /usr/local/mysql/my.cnf
log-bin =/home/data/mysql/binlog_new/mysql-bin

查看配置文件的binlog路径:

<code class=" hljs ruby">[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服务

<code class=" hljs ruby">[root@mysql5612 mysql]# service mysqld56 restart
Shutting down MySQL..                                      [确定]
Starting MySQL.....                                        [确定]
[root@mysql5612 mysql]# 

5,验证新的binlog

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

<code class=" hljs perl">[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]# 

建立新表,录入数据:

<code class=" hljs applescript">[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,表示有新的二进制日志产生了:

<code class=" hljs haml">[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表的操作记录,如下所示:

<code class=" hljs vala">[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&#160;protected]'
###   @5='[email&#160;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路径切换操作成功完成了。

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
主题背景位于 Windows 11 中的什么位置?主题背景位于 Windows 11 中的什么位置?Aug 01, 2023 am 09:29 AM

Windows11具有如此多的自定义选项,包括一系列主题和壁纸。虽然这些主题以自己的方式是美学,但一些用户仍然想知道他们在Windows11上的后台位置。本指南将展示访问Windows11主题背景位置的不同方法。什么是Windows11默认主题背景?Windows11默认主题背景是一朵盛开的抽象宝蓝色花朵,背景为天蓝色。这种背景是最受欢迎的背景之一,这要归功于操作系统发布之前的预期。但是,操作系统还附带了一系列其他背景。因此,您可以随时更改Windows11桌面主题背景。主题背景存储在Windo

二进制算法怎么算二进制算法怎么算Jan 19, 2024 pm 04:38 PM

二进制算法是一种基于二进制数的运算方法,其基本运算包括加法、减法、乘法和除法。除了基本运算外,二进制算法还包括逻辑运算、位移运算等操作。逻辑运算包括与、或、非等操作,位移运算包括左移和右移操作。这些操作都有对应的规则和操作数的要求。

如何使用C语言将二进制转换为十六进制?如何使用C语言将二进制转换为十六进制?Sep 01, 2023 pm 06:57 PM

二进制数以1和0表示。16位的十六进制数系统为{0,1,2,3…..9,A(10),B(11),……F(15)}为了从二进制表示转换为十六进制表示,位串id被分组为4位块,从最低有效侧开始称为半字节。每个块都替换为相应的十六进制数字。让我们看一个示例,以清楚地了解十六进制和二进制数字表示。001111100101101100011101&nbsp;3&nbsp;&nbsp;E&nbsp;&nbsp;5&nbsp;&nbsp;B&nb

EDVAC有哪两个重大的改进EDVAC有哪两个重大的改进Mar 02, 2023 pm 02:58 PM

EDVAC的两个重大的改进:一是采用二进制,二是完成了存贮程序,可以自动地从一个程序指令进到下一个程序指令,其作业可以通过指令自动完成。“指令”包括数据和程序,把它们用码的形式输入到机器的记忆装置中,即用记忆数据的同一记忆装置存贮执行运算的命令,这就是所谓存贮程序的新概念。

Golang能否处理二进制文件?Golang能否处理二进制文件?Mar 20, 2024 pm 04:36 PM

Golang能否处理二进制文件?在Go语言中,处理二进制文件是非常常见且方便的。通过使用内置的包和方法,我们可以轻松地读取、写入和操作二进制文件。本文将介绍如何在Go中处理二进制文件,并提供具体的代码示例。读取二进制文件要读取一个二进制文件,我们首先需要打开这个文件并创建一个对应的文件对象。然后,我们可以使用Read方法从文件中读取数据,并以字节的形式存储在

Golang如何读取二进制文件?Golang如何读取二进制文件?Mar 21, 2024 am 08:27 AM

Golang如何读取二进制文件?二进制文件是以二进制形式存储的文件,其中包含了计算机能够识别和处理的数据。在Golang中,我们可以使用一些方法来读取二进制文件,并将其解析成我们想要的数据格式。下面将介绍如何在Golang中读取二进制文件,并给出具体的代码示例。首先,我们需要使用os包中的Open函数打开一个二进制文件,这将返回一个文件对象。然后,我们可以使

轻松学会Go语言中16进制转二进制轻松学会Go语言中16进制转二进制Mar 15, 2024 pm 04:45 PM

题目:轻松学会Go语言中16进制转二进制,需要具体代码示例在计算机编程中,经常会涉及到对不同进制数之间的转换操作。其中,16进制和二进制之间的转换是比较常见的。在Go语言中,我们可以通过一些简单的代码示例来实现16进制到二进制的转换,让我们一起来学习一下。首先,我们来了解一下16进制和二进制的表示方法。16进制是一种表示数字的方法,使用0-9和A-F来表示1

在JavaFX中,有哪些不同的路径元素?在JavaFX中,有哪些不同的路径元素?Aug 28, 2023 pm 12:53 PM

javafx.scene.shape包提供了一些类,您可以使用它们绘制各种2D形状,但这些只是原始形状,如直线、圆形、多边形和椭圆形等等...因此,如果您想绘制复杂的自定义形状,您需要使用Path类。Path类Path类使用此表示形状的几何轮廓您可以绘制自定义路径。为了绘制自定义路径,JavaFX提供了各种路径元素,所有这些都可以作为javafx.scene.shape包中的类使用。LineTo-该类表示路径元素line。它可以帮助您从当前坐标到指定(新)坐标绘制一条直线。HlineTo-这是表

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는