MySQL下當我導入一個比較大的SQL文件時出現了ERROR 2006 (HY000): MySQL server has gone away
錯誤,具體狀況以下:html
> ll *.sql -rwxr-xr-x@ 1 bohan staff 27M Mar 26 18:08 91620_all.sql > mysql test < 91620_all.sql ERROR 2006 (HY000) at line 17128: MySQL server has gone away
上面能夠看到,文件大小爲27M導入的時候會報這個錯誤。mysql
If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this:sql
shell> mysql --max_allowed_packet=32M
That sets the packet size to 32MB.shell
咱們經過MySQL相關文檔能夠發現默認大小是16M。ssh
全部大於16M的SQL文件都會報這個錯誤,咱們能夠直接經過命令後增長--max_allowed_packet=32M
解決this
或者登陸MySQL客戶端,修改系統變量:code
> ssh mysql mysql> set GLOBAL max_allowed_packet=32*1024*1024;
咱們也能夠經過修改MySQL配置my.cnf
文件,在最後一行增長max_allowed_packet=32M
就能夠了server
MySQL配置文件的位置:htm
C:\ProgamData\MySQL\MySQL Server5.6
/etc/mysql
/usr/local/Cellar/mysql/5.6.23