MySQL用source命令导入不记入binlog中【原创】
试验环境,MySQL主主复制
主库10.72.16.112
从库10.72.16.50
一直有个疑问,利用sql_log_bin=0可以临时在客户端停止将操作记入binlog中,如果使用source命令导入批量SQL会有同样的效果吗。今天有事就测试了一把
对hch库的tb1表进行试验,原数据情况如下,主从数据都是一致的
主库
root@localhost:mysql.sock [hch]>select * from tb1;
+----+-------+
| id | cname |
+----+-------+
| | php |
| | java |
| | go |
| | test |
| | test1 |
| | test2 |
| | test3 |
| | test4 |
| | test5 |
| | test6 |
| | test7 |
| | test8 |
+----+-------+
rows in set (0.10 sec) 从库
mysql> select * from hch.tb1;
+----+-------+
| id | cname |
+----+-------+
| 1 | php |
| 2 | java |
| 3 | go |
| 4 | test |
| 5 | test1 |
| 6 | test2 |
| 7 | test3 |
| 8 | test4 |
| 9 | test5 |
| 10 | test6 |
| 11 | test7 |
| 12 | test8 |
+----+-------+
12 rows in set (0.01 sec)
编写sql文件
insert into tb1(cname) values('test3');
insert into tb1(cname) values('test4');
insert into tb1(cname) values('test5');
insert into tb1(cname) values('test6');
insert into tb1(cname) values('test7');
insert into tb1(cname) values('test8');
在主库上做试验
# 临时关闭sql_log_bin参数
root@localhost:mysql.sock [hch]>show variables like "sql_log_bin";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_log_bin | ON |
+---------------+-------+
row in set (0.39 sec) root@localhost:mysql.sock [hch]>set sql_log_bin=;
Query OK, rows affected (0.00 sec) root@localhost:mysql.sock [hch]>show variables like "sql_log_bin";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_log_bin | OFF |
+---------------+-------+
row in set (0.00 sec) # 执行导入sql命令
root@localhost:mysql.sock [hch]>source sql.sh;
Query OK, row affected (0.08 sec) Query OK, row affected (0.03 sec) Query OK, row affected (0.06 sec) Query OK, row affected (0.00 sec) Query OK, row affected (0.00 sec) Query OK, row affected (0.03 sec)
对比主从之间的对比结果
# 主库查询执行结果
root@localhost:mysql.sock [hch]>select * from tb1;
+----+-------+
| id | cname |
+----+-------+
| | php |
| | java |
| | go |
| | test |
| | test1 |
| | test2 |
| | test3 |
| | test4 |
| | test5 |
| | test6 |
| | test7 |
| | test8 |
| | test3 |
| | test4 |
| | test5 |
| | test6 |
| | test7 |
| | test8 |
+----+-------+
rows in set (0.00 sec) # 从库执行查询结果
mysql> select * from hch.tb1;
+----+-------+
| id | cname |
+----+-------+
| | php |
| | java |
| | go |
| | test |
| | test1 |
| | test2 |
| | test3 |
| | test4 |
| | test5 |
| | test6 |
| | test7 |
| | test8 |
+----+-------+
rows in set (0.11 sec)
主从同步状态查询
主库查询
root@localhost:mysql.sock [(none)]>show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.72.16.50
Master_User: root
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-relay-bin-503306.000004
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: b7fae014-c3af-11e8-89c1-000c29bf3444
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 22dc7409-2cd5-11e7-888c-000c29bf3444:-,
387faba7-a070-11e8--000c29466957:-,
671bac73-a032-11e8-a493-000c29bf3444:-,
909c25b1-7f67-11e8-9b9d-000c29bf3444:,
a68949d2-a06c-11e8-bba3-000c29bf3444:,
ee639e4e-358a-11e7-87fa-000c29466957:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.03 sec) 从库查询
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.72.16.112
Master_User: root
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin-1123306.000004
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 387faba7-a070-11e8--000c29466957
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 387faba7-a070-11e8--000c29466957:-
Executed_Gtid_Set: 22dc7409-2cd5-11e7-888c-000c29bf3444:-,
387faba7-a070-11e8--000c29466957:-,
671bac73-a032-11e8-a493-000c29bf3444:-,
909c25b1-7f67-11e8-9b9d-000c29bf3444:,
a68949d2-a06c-11e8-bba3-000c29bf3444:,
ee639e4e-358a-11e7-87fa-000c29466957:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.02 sec) ERROR:
No query specified
结论,可以看出设置sql_log_bin=0,用source命令导入SQL也可以不记入binlog中。
欢迎转载,请注明出处!
MySQL用source命令导入不记入binlog中【原创】的更多相关文章
- 为MySQL的source命令导入SQL文件配置参数
为MySQL的source命令导入SQL文件配置参数 执行 mysql -uroot -p 输入密码后进入 MySQL 命令提示符 set charset utf8; source /root/xxx ...
- MySQL 解决source 命令导入数据库 乱码
在我把库.表.sql脚本的编码格式都设置为UTF-8后,任然有乱码,任然有报错: 于是按以下方式重新登录后,解决: mysql -u root -p --default-character-set=u ...
- HeidiSQL、Navicat、mysql命令和source命令导入sql脚本的速度比较
一.四种导入方式的比较 1.heidisql客户端是一条一条插入的,速度最慢,而且很脆弱比较容易崩溃: 2.mysql命令导入380万记录用时1小时13分(属于前台运行的命令,ctrl+c就可以结束) ...
- source命令导入大数据速度慢优化
XX市邮政微商城的项目数据库,300多M,约220万条数据,source命令导入花了20个小时左右,太不可思议. 速度慢原因:220多万条数据,就 insert into 了220多万次,下图: 这是 ...
- source命令 导入.sql文件时,中文乱码 或者是注释乱码
1.source命令 导入.sql文件时,中文乱码 或者是注释乱码 首先进入dos命令,进入mysql数据库,之后use 数据库:之后查看你的mysql数据库编码 如下命令:模糊查询变量charact ...
- mysql 01: source命令
使用mysql的source命令,执行sql脚本 之所以使用docker同步挂载卷的方法,是因为在docker中运行的mysql未安装vim或gedit等基本编辑器 不方便在mysql容器里直接写sq ...
- MYSQL用SOURCE命令时导入乱码的问题解决
现在遇到了,但记得上次辉哥说过的方法,在MYSQL命令行里输入: set names utf8; 再执行SOURCE命令,搞定!
- 使用mysql的source批量导入多个sql文件
需求: 有一个文件,文件里面包含100多个sql文件,想要把这些sql文件都导入到mysql中 做法: 使用 mysql 的 source 可以将文件导入到 mysql 中,但是一次只能导入一个 sq ...
- mysql source命令导入sql文件效率分析和索引整理
Query OK, 24918 rows affected (0.90 sec)Records: 24918 Duplicates: 0 Warnings: 0 Query OK, 24923 r ...
随机推荐
- Python 排序和numpy排序,得到排序后索引序列(及源list的序列)
Python list 排序 & np list 排序 nums = [1.25, 0.98, 6.13, 7.62] li = np.array(nums) print(li) out = ...
- cmd命令对java程序进行编译时出现:编码GBK的不可映射字符
原因:由于JDK是国际版的,在编译的时候,如果我们没有用-encoding参数指定JAVA源程序的编码格式,则java.exe首先获得我们才做系统默认采用的编码格式,也即在编译JAVA程序时,若我们不 ...
- JAVA核心技术I---JAVA基础知识(内部类)
一:内部类概述 (一)定义 内部类(Inner Class)是定义在其他类中或方法中的类,包含内部类的类通常称作Enclosing Class 内部类的功能通常与包含它的类的功能有紧密的关联 内部类的 ...
- 设计模式---数据结构模式之迭代器模式(Iterate)
一:概念 迭代模式是行为模式之一,它把对容器中包含的内部对象的访问委让给外部类,使用Iterator(遍历)按顺序进行遍历访问的设计模式. 在应用Iterator模式之前,首先应该明白Iterator ...
- ` ` ` ` ` ` ` `
字符实体 说明 这是我们使用最多的空格,也就是按下space键产生的空格.在HTML中,如果你用空格键产生此空格,空格是不会累加的(只算1个).要使用html实体表示才可累加. 占据的宽度正好 ...
- html基本进阶知识【转】
inline和block的区别: 网页一般是两种元素组合起来的,一种是内联元素,也就是行内显示,加上width和height没效果.一种是区块元素,可以加上对应的width和height,通常使用在网 ...
- 原生JavaScript运动功能系列(四):多物体多值链式运动
原生JavaScript运动功能系列(一):运动功能剖析与匀速运动实现 原生JavaScript运动功能系列(二):缓冲运动 原生JavaScript运动功能系列(三):多物体多值运动 多物体多值链式 ...
- C语言宏定义##连接符和#符的使用
1. 关于宏(Macro) 属于编译器预处理的范畴,属于编译器概念(而非运行期概念). 2. 关于# #的功能:是 将其后面的宏参数进行 字符串化操作(Stringfication),即:在对它所引用 ...
- GIL 全局解释器
全局解释器锁 GIL 相当于给python解释器加了一把互斥锁 每一个进程都有一把互斥锁,所有线程必须先拿到解释器,才能执行代码, 同一进程下,所有线程并发 在 Cpython 解释器下,多个进程可以 ...
- 队列 Queue 与 生产者消费模型
队列:先进先出 # from multiprocessing import Queue # Q = Queue(4) # Q.put('a') # Q.put('b') # Q.put('b') # ...