新手问题 [已解决] 明明我的.sql 文件只有 82k,为什么总是提示 “ Got a packet bigger than 'max_allowed_packet' bytes” 呢?

chairy11 · 2015年03月10日 · 最后由 blacktulip 回复于 2015年03月10日 · 6588 次阅读

问题描述

迁移服务器,要把旧服务器上的 mysql 数据复制到新服务器的 mysql 上。

我先是把旧服务器的数据库用 mysqldump 复制了一份,然后想导入到新服务器,用命令导入,结果提示

ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    54350

ERROR 1231 (42000): Variable 'time_zone' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'foreign_key_checks' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'unique_checks' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'character_set_client' can't be set to the value of 'NULL'
Query OK, 0 rows affected (0.00 sec)

ERROR 1231 (42000): Variable 'collation_connection' can't be set to the value of 'NULL'
ERROR 1231 (42000): Variable 'sql_notes' can't be set to the value of 'NULL'

根据网上说的方案,我在命令行加上--max_allowed_packet=128M

mysql --max_allowed_packet=128M -u user -ppass database < database.sql 

结果还是提示 Got a packet bigger than 'max_allowed_packet' bytes

然后我又尝试用 MysqlWorkBench 客户端导入,还是提示 Got a packet bigger than 'max_allowed_packet' bytes

实在太奇怪了,明明这个.sql 文件只有 82K 啊!

解决方案(感谢@blacktulip提供)

mysql -u root -p -e "set global net_buffer_length=1000000; set global max_allowed_packet=1000000000;"

然后重启 mysqld,再正常导入就可以了……

不过我还是没明白,max_allowed_packet 默认值都有 16M,我文件才 82k,怎么就超过大小了呢?

mysql -u root -p -e "set global net_buffer_length=1000000; set global max_allowed_packet=1000000000;"

然后重启 mysqld

#1 楼 @blacktulip 我我我,不会重启 mysqld……

[root@aaa ~]#   ps auxw | grep mysql
root      1836  0.0  0.0 108164  1620 ?        S     2014   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/aaa.pid
mysql     1940  0.0  0.8 2263088 554756 ?      Sl    2014  44:40 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/aaa.err --pid-file=/var/lib/mysql/aaa.pid
root      6185  0.0  0.0 103248   892 pts/1    S+   10:30   0:00 grep mysql



[root@aaa ~]# /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/aaa.err --pid-file=/var/lib/mysql/aaa.pid restart
2015-03-10 10:31:40 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

#2 楼 @chairy11 service mysqld restart

#3 楼 @marksloan 这个我刚才就试过了,说是

service mysqld restart
mysqld: 未被识别的服务

service mysql restart 行不行 (mysql 后面不加 d )?你的 mysql 是怎么安装上去的?

实在不会重启 mysql,你就整台服务器 reboot 好了

#5 楼 @blacktulip 这是 centos,这个 mysql 之前就有的,因为里面还有别人的数据库,我就没有重装了…… service mysql restart不行啊,说是未被识别的服务。 前面我用ps auxw | grep mysql抄来一大段连着配置的句子,

[root@aaa ~]# /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/aaa.err --pid-file=/var/lib/mysql/aaa.pid restart

2015-03-10 10:31:40 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

它又说要什么 TIMESTAMP,可我不能自己在哪里给写个时间上去吧?

#5 楼 @blacktulip 哦,我知道了,我刚才用的是service mysqld restart ,多写了个 d ,现在用

[root@aaa ~]# service mysql stop
Shutting down MySQL.... SUCCESS! 

[root@aaa~]# service mysql start
Starting MySQL. SUCCESS! 

好像好了…… 我再试试导入看看 max_allowed_packet 设置生效没……

#3 楼 @marksloan 不是mysqld,要用mysql 哦……

#5 楼 @blacktulip 好了好了!太开心了!谢谢谢谢!

#5 楼 @blacktulip 不过我还是没明白,max_allowed_packet 默认值好像是 16M,我文件才 82k,怎么就超过大小了呢?

这个我也不清楚...

需要 登录 后方可回复, 如果你还没有账号请 注册新账号