我如何在 MYSQL 中运行查询而不将其写入二进制日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2958479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i run a query in MYSQL without writing it to the binary log
提问by Kibbee
I want to run an import of a large file into MySQL. However, I don't want it written to the binary log, because the import will take a long time, and cause the slaves to fall far behind. I would rather run it seperately on the slaves, after the fact, because it will be much easier on the system. The table in question is a new one, and therefore I don't really have to worry about it getting out of sync, as the master and all the slaves will have the same data in the end, because they will all import the same file eventually. I also don't want to change any of the replicate-ignore-* or binlog_ignore-* options, because they require a restart of the servers in question. Is there a a way to run a single query without writing it to the binary log?
我想将一个大文件导入 MySQL。但是,我不希望它写入二进制日志,因为导入会花费很长时间,并且导致从属远远落后。事实上,我宁愿在奴隶上单独运行它,因为它在系统上会容易得多。有问题的表是一个新表,因此我真的不必担心它会不同步,因为主站和所有从站最终将拥有相同的数据,因为它们都将导入相同的文件最终。我也不想更改任何 replica-ignore-* 或 binlog_ignore-* 选项,因为它们需要重新启动相关服务器。有没有一种方法可以运行单个查询而不将其写入二进制日志?
I already know the answer, but I couldn't find it very easily on the net, so I'm letting somebody post the answer to get some rep points. If there's no answers in a little white I'll post the answer I found.
我已经知道答案了,但是我在网上很难找到它,所以我让某人发布答案以获得一些代表积分。如果没有一点白色的答案,我会发布我找到的答案。
回答by Kibbee
You can use the sql-log-binsession variable to turn off logging for the current session. Just simply enter:
您可以使用sql-log-bin会话变量来关闭当前会话的日志记录。只需简单地输入:
SET sql_log_bin = 0;
and all queries on your current session will not be sent to the binary log. If you want to turn binary logging back on, run:
并且您当前会话的所有查询都不会发送到二进制日志。如果要重新打开二进制日志记录,请运行:
SET sql_log_bin = 1;
This is only for the currently running session you are in. All other queries from all other connections will still continued to be logged. Also, you must have SUPER privileges for this to work.
这仅适用于您所在的当前正在运行的会话。来自所有其他连接的所有其他查询仍将继续记录。此外,您必须具有 SUPER 权限才能使其正常工作。
回答by Mihai
If you want to do this from the cli, try this, it worked for me:
如果您想从 cli 执行此操作,请尝试此操作,它对我有用:
$ mysqldump old_DB | mysql --init-command="SET SQL_LOG_BIN = 0;" new_DB
Possible that the "init-command" param was added in a newer MySQL version.
可能是在较新的 MySQL 版本中添加了“init-command”参数。