因为init_command 导致的 mysql 5.6 主从连接失败的案例一则。

mysql  5.6 从库主机安排了计划性重启,  重启主机后, 问题来了。
实例 无法连接master 了。 

报错如下:

[code]
2018-09-17 12:21:50 28554 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='192.168.8.42', master_port= 3307, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='192.168.8.42', master_port= 3307, master_log_file='', master_log_pos= 4, master_bind=''.2018-09-17 12:21:58 28554

 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended.

 Please consider using the USER and PASSWORD connection options for START SLAVE; 

see the 'START SLAVE Syntax' in the MySQL Manual for more information.2018-09-17 12:21:58 28554

[Note] Slave SQL thread initialized, starting replication in log 'FIRST' at position 0, relay log './relay-bin.000001' position: 42018-09-17 12:21:58 28554

 [Note] Slave I/O thread: connected to master 'repl@192.168.8.42:3307',replication started in log 'FIRST' at position 42018-09-17 12:21:58 28554

 [Warning] "SELECT UNIX_TIMESTAMP()" failed on master, do not trust column Seconds_Behind_Master of SHOW SLAVE STATUS. Error: Aborted connection 12505106 to db: 'unconnected' user: 'repl' host: '192.168.8.43' (init_connect command failed) (1184)2018-09-17 12:21:58 28554 [ERROR] Slave I/O: The slave I/O thread stops because a fatal error is encountered  when it tries to SET @master_heartbeat_period on master. Error: , Error_code: 15932018-09-17 12:21:58 28554 

[Note] Slave I/O thread exiting, read up to log 'FIRST', position 4
[/code]

咋回事呢, 同事重置了slave 还是报错。 

因为启用了gtid  , 两边对照了gtid 的各个参数都是一致的。 也排除了gtid 的故障。 

因为重启之前都是OK 的, 也不存数据问题。 纳闷了。 

看日志就上上面这样了。 

一时没明白过来。 去主库上看看 。 

问题找到了。 

#init_connect='set names gbk;insert into db_monitor.accesslog(thread_id,log_time,localname,matchname) values(connection_id(),now(),user(),current_user());commit;'

主库上的init_command  参数 加了一条sql 语句。 

对应到了日志里的 init_command 的报错。 

看看权限 

[code]

mysql.sock@(none)> use mysql 

Database changed

mysql.sock@mysql> select * from  tables_priv   ;

+------+------------+--------------+------------+----------------+---------------------+------------+-------------+

| Host | Db         | User         | Table_name | Grantor        | Timestamp           | Table_priv | Column_priv |

+------+------------+--------------+------------+----------------+---------------------+------------+-------------+

| %    | db_monitor | user_app | accesslog  | root@localhost | 0000-00-00 00:00:00 | Insert     |             |

+------+------------+--------------+------------+----------------+---------------------+------------+-------------+

1 row in set (0.02 sec)

mysql.sock@mysql> 

[/code]

把init_command   注释掉后,  一切都ok 了。 

原来之前因为某个事件 , 增加了一点审计功能, 就用init_command  实现了。 

原来是忘记给repl 授权了。  

导致  repl 再次登录的时候, 无权操作这个insert 语句报错。退出了。无法连接master . 

此则 案例记录之。 


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/133735/viewspace-2214315/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/133735/viewspace-2214315/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值