试验环境,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 |
+----+-------+
|  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.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    |
+---------------+-------+
1 row in set (0.39 sec)root@localhost:mysql.sock [hch]>set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)root@localhost:mysql.sock [hch]>show variables like "sql_log_bin";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_log_bin   | OFF   |
+---------------+-------+
1 row in set (0.00 sec)# 执行导入sql命令
root@localhost:mysql.sock [hch]>source sql.sh;
Query OK, 1 row affected (0.08 sec)Query OK, 1 row affected (0.03 sec)Query OK, 1 row affected (0.06 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.00 sec)Query OK, 1 row affected (0.03 sec)

对比主从之间的对比结果

# 主库查询执行结果
root@localhost:mysql.sock [hch]>select * from 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 |
| 13 | test3 |
| 14 | test4 |
| 15 | test5 |
| 16 | test6 |
| 17 | test7 |
| 18 | test8 |
+----+-------+
18 rows in set (0.00 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.11 sec)

主从同步状态查询

主库查询
root@localhost:mysql.sock [(none)]>show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 10.72.16.50Master_User: rootMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000002Read_Master_Log_Pos: 11626109Relay_Log_File: mysql-relay-bin-503306.000004Relay_Log_Pos: 367Relay_Master_Log_File: mysql-bin.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 11626109Relay_Log_Space: 628Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 503306Master_UUID: b7fae014-c3af-11e8-89c1-000c29bf3444Master_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_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:1-984109,
387faba7-a070-11e8-8674-000c29466957:1-53880,
671bac73-a032-11e8-a493-000c29bf3444:1-10,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
a68949d2-a06c-11e8-bba3-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753Auto_Position: 1Replicate_Rewrite_DB: Channel_Name: 503306Master_TLS_Version:
1 row in set (0.03 sec)从库查询
mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 10.72.16.112Master_User: rootMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos: 323113389Relay_Log_File: relay-bin-1123306.000004Relay_Log_Pos: 11660372Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 323113389Relay_Log_Space: 145879191Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 56Master_UUID: 387faba7-a070-11e8-8674-000c29466957Master_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 387faba7-a070-11e8-8674-000c29466957:70-53880Executed_Gtid_Set: 22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
387faba7-a070-11e8-8674-000c29466957:1-53880,
671bac73-a032-11e8-a493-000c29bf3444:1-10,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
a68949d2-a06c-11e8-bba3-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753Auto_Position: 1Replicate_Rewrite_DB: Channel_Name: 1123306Master_TLS_Version:
1 row in set (0.02 sec)ERROR:
No query specified

结论,可以看出设置sql_log_bin=0,用source命令导入SQL也可以不记入binlog中。

欢迎转载,请注明出处!

转载于:https://www.cnblogs.com/paul8339/p/9789801.html

MySQL用source命令导入不记入binlog中【原创】相关推荐

  1. mysql 参数sql文件_为MySQL的source命令导入SQL文件配置参数

    为MySQL的source命令导入SQL文件配置参数 执行 mysql -uroot -p 输入密码后进入 MySQL 命令提示符 set charset utf8; source /root/xxx ...

  2. mysql数据库source命令导入sql文件

    在导入大的sql文件时,使用可视化工具导入往往效率极低,此时,我们常常使用在cmd中执行source命令的方式 第一步,打开cmd命令窗口,进入数据库 mysql  -u用户名  -p 输入密码 第二 ...

  3. mysql数据库source命令导入sql文件记录

    第一步:打开cmd命令窗口,进入数据库 第二步:创建数据库 mysql> create database demo; 第三步:source 导入sql文件 Bug1 mysql> sour ...

  4. MySQL的source命令

    用MySQL的source命令导入SQL文件实战记录. 进入 CMD 执行 mysql -uroot -p 输入密码后进入 MySQL 命令提示符 依次执行: use XXXdatabase; set ...

  5. mysql source 导入本地文件_MySQL可使用source 命令导入本地sql脚本文件( )。

    [多选题]葡萄酒封装作为最重要的一个流程,极大部分采用自动化.以下选项中属于葡萄酒封装线程序的是(). [单选题]CMYK 模型中的 K 表示何种颜色,该模式主要用于打印行业 [单选题]下列哪项不是二 ...

  6. MySQL 数据库 source 命令详解及实例

    MySQL 数据库 source 命令详解及实例 MySQL 数据库 source 命令,该命令是数据库导入命令.source 命令的用法非常简单,首先你需要进入 MySQL 数据库的命令行管理界面, ...

  7. mysql数据库使用命令导入sql文件

    第一步: 在数据库安装目录下打开cmd窗口 第二步: 输入命令登录数据库: mysql -u root -p 回车 输入密码 回车 第三步: 创建数据库命令: create database 数据库名 ...

  8. MySQL的source命令不加分号和delimiter的使用

    [0]README 0.1)本文旨在 review source 命令, 这一直是我的痛,为什么一直导入 sql 文件不成功,一直没有写 blog 吧他 记录下来(事实上,也间接证明我就是个小白): ...

  9. 包+类导入+静态导入+类放入包中+包作用域

    [0]README 0.1)本文转自 core java volume 1, 旨在理清 包和类导入的相关知识: [1] 包 1.1) java 允许使用包将类组织起来,包可以方便组织代码,并将自己的代 ...

最新文章

  1. Vmware vSphere 5.0安装和配置
  2. android 深度定制,深度定制安卓是什么
  3. linux 路由 route命令
  4. shell 变量定义使用
  5. java栈的实现_栈的实现(Java)
  6. vs2013 c# 中调用 c 编写的dll出错的可能错误
  7. C++:46---绝不重新定义继承而来的non-virtual函数
  8. java.util.UnknownFormatConversionException: Conversion = ‘,‘ 解决
  9. .svn文件夹_SVN下载安装及使用教程(二)
  10. linux安装typecho教程,Typecho上手指南
  11. 2009年即将过去,准备迎接2010
  12. Php获取分类等级,PHP获取无限分类的完整等级列表
  13. Mysql集群方案简介
  14. 【从零开始学习Go语言】一.初识Go语言
  15. 饱和和非饱和激活函数
  16. php cgi sapi
  17. 汽配供应链管理系统:助力汽配企业实现采购业务全过程数字化管理
  18. 编写微信聊天机器人2《聊天精灵WeChatGenius》:引入Xposed库,使模块生效。
  19. Smiditor实现图片上传功能
  20. 2022年数维杯数学建模C题 电动汽车充电站的部署优化策略求解全过程文档及程序

热门文章

  1. 网页中嵌入地图位置方法
  2. VMware介绍与网络的三种模式
  3. 网站制作之按钮onclick大全
  4. Java 集合框架综述
  5. 大型分布式网站术语分析 15 条,你知道几条?
  6. 多线程:一些好的编程建议
  7. 多进程和多线程的区别
  8. Python for else 的使用(银行账号的登录)
  9. 用java写游戏_用java写的扫雷游戏
  10. html怎么设置图片倾斜度,CSS3-css如何使图片倾斜45度显示