MySQL mysql中的二进制日志错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11445678/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:09:17  来源:igfitidea点击:

Binary log error in mysql

mysql

提问by Ajay Kadyan

When I am trying to check binary log:

当我尝试检查二进制日志时:

 SHOW BINARY LOGS;

I get this error:

我收到此错误:

ERROR 1381 (HY000): You are not using binary logging.

错误 1381 (HY000):您没有使用二进制日志记录。

How to resolve this? Can anybody help?

如何解决这个问题?有人可以帮忙吗?

回答by Shlomi Noach

Set the log-binvariable in your MySQL configuration file, then restart MySQL.

log-bin在 MySQL 配置文件中设置变量,然后重新启动 MySQL。

An example my.cnf(on Linux/unix) or my.ini(on Windows) would look like:

一个示例my.cnf(在 Linux/unix 上)或my.ini(在 Windows 上)如下所示:

[client]
...

[mysqld]
...
log-bin=mysql-bin
---

Once restarted, MySQL automatically creates a new binary log (does so upon every restart). You may also wish to look at the following variables:

重新启动后,MySQL 会自动创建一个新的二进制日志(每次重新启动时都会这样做)。您可能还希望查看以下变量:

server-id        = 1
expire_logs_days = 4
sync_binlog      = 1

Read details on the MySQL documentation. If you're after replication setup (a primary reason for using binary logs), check out Replication configuration checklist.

阅读有关MySQL 文档的详细信息。如果您在复制设置之后(使用二进制日志的主要原因),请查看复制配置清单

回答by user2545009

Line

线

log-bin=mysql-bin

must placed above lines:

必须放在行上方:

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

回答by RolandoMySQLDBA

You will need to activate binary logging at startup

您需要在启动时激活二进制日志记录

Add the following lines in /etc/my.cnf under the [mysqld] section

在 [mysqld] 部分下的 /etc/my.cnf 中添加以下行

[mysqld]
log-bin=mysql-bin
expire-logs-days=7

Then, run this

然后,运行这个

service mysql restart

The next time you login to mysql, you will see a binary log listing and will rotate out after 7 days.

下次登录 mysql 时,您将看到一个二进制日志列表,并将在 7 天后轮换。

The default location of the binary logs will be /var/lib/mysqlor where datadir is defined. If you specify a folder before the binlog name, then that folder is the location.

二进制日志的默认位置将是/var/lib/mysql或 定义 datadir 的位置。如果在 binlog 名称之前指定文件夹,则该文件夹就是位置。

For example

例如

[mysqld]
log-bin=/var/log/mysql-bin
expire-logs-days=7

UPDATE 2012-07-12 02:20 AM EDT

更新 2012-07-12 02:20 AM EDT

Please restart mysql as follows and tell us if binary logging in on

请按如下方式重启mysql并告诉我们是否二进制登录

service mysql restart --log-bin=mysql-bin

回答by elishamint

FWIW, I had the same issue after I tried to set up my.cnf.masterand my.cnf.slavefiles and symlinkthem to my.cnffor master and slave, respectively. The idea was to be able to switch the machine from master to slave and back easily.

FWIW,在我尝试设置my.cnf.mastermy.cnf.slave文件并将它们分别符号链接my.cnf以用于 master 和 slave后,我遇到了同样的问题。这个想法是能够轻松地将机器从主机切换到从机,然后再切换回来。

It turned out that mysqld simply did not handle the symlink as expected. Hard-linkingthe file worked (ln my.cnf.master my.cnf). Careful if you do something like this, as overwriting one of the hard-linked filenames could break the link and create two separate files instead (depending on the method of rewriting employed by the software you use for it).

事实证明,mysqld 根本没有按预期处理符号链接。硬链接文件有效(ln my.cnf.master my.cnf)。如果你做这样的事情要小心,因为覆盖一个硬链接的文件名可能会破坏链接并创建两个单独的文件(取决于你使用的软件所采用的重写方法)。

回答by Arun Jain

To enable the binary log, start the server with the --log-bin[=base_name] option.

要启用二进制日志,请使用 --log-bin[=base_name] 选项启动服务器。

If no base_name value is given, the default name is the value of the pid-file option (which by default is the name of host machine) followed by -bin.

如果未给出 base_name 值,则默认名称为 pid-file 选项的值(默认为主机名称),后跟 -bin。

If the basename is given, the server writes the file in the data directory unless the basename is given with a leading absolute path name to specify a different directory. It is recommended that you specify a basename.

如果给出了 basename,则服务器会将文件写入数据目录中,除非 basename 带有前导绝对路径名以指定不同的目录。建议您指定一个基本名称。

Or you can directly use:

或者你可以直接使用:

log-bin=mysql-bin

and then restart your mysql service. Then binary file will be generated. If you are using lampp on Linux machine then you will find this file in /lampp/var/mysql/mysql-bin.000001

然后重启你的mysql服务。然后将生成二进制文件。如果你在 Linux 机器上使用 lampp 那么你会在 /lampp/var/mysql/mysql-bin.000001 中找到这个文件

回答by mahemoff

I've found logging will silently fail to happen even if my.cnf config is right, so you can also try re-creating your log folder.

我发现即使 my.cnf 配置正确,日志记录也不会发生,因此您也可以尝试重新创建日志文件夹。

This may be necwssary if the logs are in an odd state. (In my case, I had simply ceased logging in my.cnf and then re-enabled it, but nothing happened, probably because the existing files were not the latest updates?).

如果日志处于奇怪的状态,这可能是必要的。(就我而言,我只是停止登录 my.cnf 然后重新启用它,但没有任何反应,可能是因为现有文件不是最新更新?)。

Something like this should work:

这样的事情应该工作:

sudo service mysql stop
sudo mv /var/log/mysql /tmp/mysqlold # or rm -fr if you're brave
mkdir /var/log/mysql
chown -R mysql:mysql /var/log/mysql
sudo service mysql start

Obligatory warning:Obviously, take care when deleting anything on a database server. This will destroy/disrupt/corrupt any replication using this database as master (though you can resume replication as a slave). That said, I believe this should be safe insofar as it doesn't delete the database itself.

强制性警告:显然,删除数据库服务器上的任何内容时要小心。这将破坏/中断/损坏使用此数据库作为主数据库的任何复制(尽管您可以作为从属数据库恢复复制)。也就是说,我相信这应该是安全的,因为它不会删除数据库本身。

回答by gatorreina

I went out of my mind with this issue on a MySQL 5.5 master running Debian. None of the above worked. Finally, I rebooted the server and logging was enabled.

在运行 Debian 的 MySQL 5.5 master 上,我对这个问题发疯了。以上都没有奏效。最后,我重新启动了服务器并启用了日志记录。

回答by ??ng Hoàng Nguy?n

Remove section [mysqld_safe] and replace with [mysqld]. It works for me.

删除部分 [mysqld_safe] 并替换为 [mysqld]。这个对我有用。