为 Mysql 5.6 & Ubuntu16.4 设置 binlog

Posted

技术标签:

【中文标题】为 Mysql 5.6 & Ubuntu16.4 设置 binlog【英文标题】:Set binlog for Mysql 5.6 & Ubuntu16.4 【发布时间】:2019-03-15 03:00:34 【问题描述】:

在 /etc/mysql/my.cnf:

[mysqld]
log_bin=mysql-bin
binlog_format=ROW
server-id=11

然后在mysql客户端上:

mysql> show variables like '%binlog%';
+-----------------------------------------+----------------------+
| Variable_name                           | Value                |
+-----------------------------------------+----------------------+
| binlog_cache_size                       | 32768                |
| binlog_checksum                         | CRC32                |
| binlog_direct_non_transactional_updates | OFF                  |
| binlog_format                           | STATEMENT            |
| binlog_max_flush_queue_time             | 0                    |
| binlog_order_commits                    | ON                   |
| binlog_row_image                        | FULL                 |
| binlog_rows_query_log_events            | OFF                  |
| binlog_stmt_cache_size                  | 32768                |
| innodb_api_enable_binlog                | OFF                  |
| innodb_locks_unsafe_for_binlog          | OFF                  |
| max_binlog_cache_size                   | 18446744073709547520 |
| max_binlog_size                         | 1073741824           |
| max_binlog_stmt_cache_size              | 18446744073709547520 |
| sync_binlog                             | 0                    |
+-----------------------------------------+----------------------+
15 rows in set (0.00 sec)

我用谷歌搜索“my.cnf 不生效”并得到“对 my.cnf 的更改不生效(Ubuntu 16.04,mysql 5.6)” Changes to my.cnf don't take effect (Ubuntu 16.04, mysql 5.6)

我已经测试了这两个答案。但是当我用sudo service mysql start启动mysql时,总是出现这个错误:

/etc/init.d/mysql[27197]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
/etc/init.d/mysql[27197]: [61B blob data]
/etc/init.d/mysql[27197]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
/etc/init.d/mysql[27197]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
/etc/init.d/mysql[27197]: 
mysql[26527]:    ...fail!
systemd[1]: mysql.service: Control process exited, code=exited status=1
systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.

我花了两天时间寻找答案,但仍然没有找到任何有用的东西。有人可以帮我吗?谢谢!

【问题讨论】:

【参考方案1】:

    重新安装 MySQL

    根据以下内容清理 MySQL: https://askubuntu.com/questions/172514/how-do-i-uninstall-mysql

    sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
    sudo rm -rf /etc/mysql /var/lib/mysql
    sudo apt-get autoremove
    sudo apt-get autoclean
    

    还有https://www.jianshu.com/p/c76b31df5d09

    dpkg -l |grep ^rc|awk 'print $2' |sudo xargs dpkg -P
    

    sudo apt-get install mysql-server-5.6安装

    使my.cnf中的更改生效

    Keeth(user:20588) 的第二个回答 Changes to my.cnf don't take effect (Ubuntu 16.04, mysql 5.6)

    通过编辑/etc/mysql/my.cnf配置binlog

        [mysqld]
        log_bin=mysql-bin
        binlog_format=ROW
        server-id=11
    

【讨论】:

以上是关于为 Mysql 5.6 & Ubuntu16.4 设置 binlog的主要内容,如果未能解决你的问题,请参考以下文章

MySQL最优配置模板( 5.6&5.7转)

MySQL 5.6安装

mac 装5.6版本mysql 设置密码

Linux安装MySQL_5.6

MySQL 5.6 主从报错一例

MySQL 5.6 主从报错一例