简体   繁体   English

mysql中的二进制日志错误

[英]Binary log error in mysql

When I am trying to check binary log: 当我试图检查二进制日志时:

 SHOW BINARY LOGS;

I get this error: 我收到此错误:

ERROR 1381 (HY000): You are not using binary logging. ERROR 1381(HY000):您没有使用二进制日志记录。

How to resolve this? 怎么解决这个? Can anybody help? 有人可以帮忙吗?

Set the log-bin variable in your MySQL configuration file, then restart MySQL. 在MySQL配置文件中设置log-bin变量,然后重启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). 重新启动后,MySQL会自动创建一个新的二进制日志(每次重启时都会这样做)。 You may also wish to look at the following variables: 您可能还希望查看以下变量:

server-id        = 1
expire_logs_days = 4
sync_binlog      = 1

Read details on the MySQL documentation . 阅读MySQL文档的详细信息。 If you're after replication setup (a primary reason for using binary logs), check out Replication configuration checklist . 如果您正在进行复制设置(使用二进制日志的主要原因),请查看复制配置清单

Line 线

log-bin=mysql-bin

must placed above lines: 必须放在线上方:

[mysqld_safe]

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

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

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/mysql or where datadir is defined. 二进制日志的默认位置是/var/lib/mysql或定义了datadir的位置。 If you specify a folder before the binlog name, then that folder is the location. 如果在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美国东部时间

Please restart mysql as follows and tell us if binary logging in on 请按如下所示重新启动mysql,并告诉我们二进制登录是否已经登录

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

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. 如果给出了basename,则服务器会将该文件写入数据目录,除非为basename指定了一个前导绝对路径名以指定其他目录。 It is recommended that you specify a basename. 建议您指定基名。

Or you can directly use: 或者您可以直接使用:

log-bin=mysql-bin

and then restart your mysql service. 然后重新启动你的mysql服务。 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 如果您在Linux机器上使用lampp,那么您将在/lampp/var/mysql/mysql-bin.000001中找到此文件

FWIW, I had the same issue after I tried to set up my.cnf.master and my.cnf.slave files and symlink them to my.cnf for master and slave, respectively. FWIW,我尝试设置my.cnf.mastermy.cnf.slave文件并将它们符号链接my.cnf分别为master和slave后,我遇到了同样的问题。 The idea was to be able to switch the machine from master to slave and back easily. 我们的想法是能够轻松地将机器从主设备切换到从设备。

It turned out that mysqld simply did not handle the symlink as expected. 事实证明,mysqld根本没有按预期处理符号链接。 Hard-linking the file worked ( ln my.cnf.master my.cnf ). 硬链接文件工作( 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). 如果你做这样的事情,请小心,因为覆盖其中一个硬链接文件名可能会破坏链接并创建两个单独的文件(取决于您使用的软件所使用的重写方法)。

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. 也就是说,我认为这应该是安全的,因为它不会删除数据库本身。

I went out of my mind with this issue on a MySQL 5.5 master running Debian. 在运行Debian的MySQL 5.5主机上,我忘记了这个问题。 None of the above worked. 以上都没有奏效。 Finally, I rebooted the server and logging was enabled. 最后,我重新启动了服务器并启用了日志记录。

Remove section [mysqld_safe] and replace with [mysqld]. 删除[mysqld_safe]部分并替换为[mysqld]。 It works for me. 这个对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM