因mysql从库报错Last_IO_Error: Got a packet bigger than 'max_allowed_packet' bytes
mysql> show slave statusG; *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.90.190 Master_User: rsync Master_Port: 3311 Connect_Retry: 60 Master_Log_File: mysql-bin.001891 Read_Master_Log_Pos: 897184977 Relay_Log_File: mysql-relay-bin.003780 Relay_Log_Pos: 897185056 Relay_Master_Log_File: mysql-bin.001891 Slave_IO_Running: No Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 897184910 Relay_Log_Space: 897185322 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 1153 Last_IO_Error: Got a packet bigger than 'max_allowed_packet' bytes Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 row in set (0.00 sec)
第一步:先登录数据库,查看 max_allowed_packet 这个参数值
连接数据库服务器,登录 mysql, 执行命令 : show variables like '%max_allowed_packet%'; 默认是1M
mysql> show variables like '%max_allowed_packet%'; +--------------------+---------+ | Variable_name | Value | +--------------------+---------+ | max_allowed_packet | 1048576 | +--------------------+---------+ 1 row in set (0.00 sec)
第二步:set global max_allowed_packet = 100 *1024*1024;
mysql> set global max_allowed_packet = 100 *1024*1024; Query OK, 0 rows affected (0.00 sec) #接着查看没有变过来,需要退出重新登陆,查看的是原始值(缓存) mysql> show variables like '%max_allowed_packet%'; +--------------------+---------+ | Variable_name | Value | +--------------------+---------+ | max_allowed_packet | 1048576 | +--------------------+---------+ 1 row in set (0.00 sec)
第三步:重新登陆确认是否生效:
mysql> show variables like '%max_allowed_packet%'; +--------------------+-----------+ | Variable_name | Value | +--------------------+-----------+ | max_allowed_packet | 104857600 | +--------------------+-----------+ 1 row in set (0.00 sec)
第四步:重启slave
mysql> stop slave; Query OK, 0 rows affected (0.02 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec) mysql> show slave statusG; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.90.90 Master_User: rsync Master_Port: 3311 Connect_Retry: 60 Master_Log_File: mysql-bin.001891 Read_Master_Log_Pos: 948459439 Relay_Log_File: mysql-relay-bin.003780 Relay_Log_Pos: 897185056 Relay_Master_Log_File: mysql-bin.001891 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 897184910 Relay_Log_Space: 948459887 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 1356 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
第五步:修改配置文件
修改配置文件--Linux在 Linux 中,MySQL 对应的配置文件是 my.cnf , 我们在Linux终端输入如下命令 :
[root@192-168-90-90 ~]# mysql --help | grep my.cnf order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
#如果在启动时没有指定my.cnf 就优先列表,先找到的配置文件生效
[root@192-168-90-90 data3311]# more my.cnf [mysqld] basedir=/usr/local/mysql5.5 datadir=/home/mysql5.5/data3311 tmpdir=/home/mysql5.5/data3311/temp port = 3311 server_id = 3311 socket=/home/mysql5.5/data3311/mysql3311.sock character_set_server='utf8' max_allowed_packet=100M