参考:http://www.111cn.net/database/mysql/106911.htm

1、修改mysqld的配置文件my.cnf

调整max_allowed_packet的值,修改为5M就比较合适了。

  1. [mysqld]
  2. port = 3308
  3. socket = /dev/shm/mysqld.sock
  4. skip-external-locking
  5. key_buffer_size = 16M
  6. max_allowed_packet = 10M
  7. table_open_cache = 64
  8. sort_buffer_size = 512K
  9. net_buffer_length = 8K
  10. read_buffer_size = 256K
  11. read_rnd_buffer_size = 512K
  12. myisam_sort_buffer_size = 8M

2、修改[mysqld]中的值

  1. [mysqldump]
  2. quick
  3. max_allowed_packet = 10M

感觉这篇分析的非常详细,可以对参考下

http://ronaldbradford.com/blog/sqlstatehy000-general-error-2006-mysql-server-has-gone-away-2013-01-02/

This would have to be one of the most common MySQL error messages that is misleading to the end user developer. The MySQL Manual page confirms the broad range of possible conditions, but offers little to a PHP developer that does not speak MySQL Geek. I am commonly asked to help solve this issue from a developer.

The problem is that there are several conditions that can cause this error, and a more meaningful explanation to the end user would help in addressing the issue. In general terms, this actually means “Your SQL statement has failed because the connection to the database has been disconnected because of ???”.

Here are a few common situations and how to check for what “???” is.

1. Your MySQL server really did go away.

We can easily check this by looking at the server uptime and the server error log.

  1. $ mysql -uroot -p -e "show global status like 'uptime';"
  2. +---------------+-------+
  3. | Variable_name | Value |
  4. +---------------+-------+
  5. | Uptime | 68928 |
  6. +---------------+-------+
  7. 1 row in set (0.04 sec)
  1. $ tail /var/log/mysql/error.log
  2. 130101 22:22:30 InnoDB: Initializing buffer pool, size = 256.0M
  3. 130101 22:22:30 InnoDB: Completed initialization of buffer pool
  4. 130101 22:22:30 InnoDB: highest supported file format is Barracuda.
  5. 130101 22:22:30 InnoDB: 1.1.8 started; log sequence number 63444325509
  6. 130101 22:22:30 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
  7. 130101 22:22:30 [Note] - '127.0.0.1' resolves to '127.0.0.1';
  8. 130101 22:22:30 [Note] Server socket created on IP: '127.0.0.1'.
  9. 130101 22:22:30 [Note] Event Scheduler: Loaded 0 events
  10. 130101 22:22:30 [Note] /usr/sbin/mysqld: ready for connections.
  11. Version: '5.5.28-cll' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)

In both these cases, the server has been up some time, and there are zero error messages to indicate problems.

If the MySQL server did go away, was it shutdown or did it crash? The MySQL error log will provide the answers. Generally the mysql daemon (mysqld) will be restarted by the mysqld_safe wrapper process.

2. The connection timed out

  1. $ mysql -uroot -p -e "show global variables like '%timeout';"
  2. +----------------------------+----------+
  3. | Variable_name | Value |
  4. +----------------------------+----------+
  5. | connect_timeout | 30 |
  6. | delayed_insert_timeout | 300 |
  7. | innodb_lock_wait_timeout | 50 |
  8. | innodb_rollback_on_timeout | OFF |
  9. | interactive_timeout | 28800 |
  10. | lock_wait_timeout | 31536000 |
  11. | net_read_timeout | 30 |
  12. | net_write_timeout | 60 |
  13. | slave_net_timeout | 3600 |
  14. | wait_timeout | 28800 |
  15. +----------------------------+----------+

These values are relatively sane MySQL defaults. If however you have very short timeouts, you may get this error. Here is just one example.

  1. mysql> SET SESSION wait_timeout=5;
  2. ## Wait 10 seconds
  3. mysql> SELECT NOW();
  4. ERROR 2006 (HY000): MySQL server has gone away
  5. No connection. Trying to reconnect...
  6. Connection id: 132361
  7. Current database: *** NONE ***
  8. +---------------------+
  9. | NOW() |
  10. +---------------------+
  11. | 2013-01-02 11:31:15 |
  12. +---------------------+
  13. 1 row in set (0.00 sec)

3. Your SQL statement was killed

Some systems will proactively kill SQL statements that have been running too long. You can easily check if this may be happening proactively by looking at how many KILL statements have been executed.

  1. $ mysql -uroot -p -e "show global status like 'com_kill'"
  2. +---------------+-------+
  3. | Variable_name | Value |
  4. +---------------+-------+
  5. | Com_kill | 0 |
  6. +---------------+-------+
  7. Not killed this time.

4. Your SQL statement was too large.

A little harder to test and verify, but MySQL uses a maximum packet site for communications between the server and the client. If this includes large fields (for example BLOB columns), you may be getting a termination of your SQL statement due to size.

By default this is relatively small.

  1. mysql> show global variables like 'max_allowed_packet';
  2. +--------------------+---------+
  3. | Variable_name | Value |
  4. +--------------------+---------+
  5. | max_allowed_packet | 1048576 |
  6. +--------------------+---------+
  7. 1 row in set (0.00 sec)

You can increase, for example to 16M with:

  1. mysql> set global max_allowed_packet=1024*1024*16;
  2. mysql> show global variables like 'max_allowed_packet';
  3. +--------------------+----------+
  4. | Variable_name | Value |
  5. +--------------------+----------+
  6. | max_allowed_packet | 16777216 |
  7. +--------------------+----------+
  8. 1 row in set (0.00 sec)

The good news, is this was the cause for the customer today, and now no more errors!

Be sure to keep this value during MySQL restarts.

  1. #my.cnf
  2. [mysqld]
  3. max_allowed_packet = 16M

and then , you need restart you mysql server .

MySQL_解决ERROR 2006 (HY000) at line XX MySQL server has gone away问题的更多相关文章

  1. ERROR 2006 (HY000) at line xx: MySQL server has gone away 解决方法

  2. [mysq]ERROR 2006 (HY000) at line xx: MySQL server has gone away 解决方法

    vi /etc/my.cnf wait_timeout=2880000interactive_timeout = 2880000max_allowed_packet = 100M 完整配置文件 [my ...

  3. mysql恢复和数据导入的问题(ERROR 2006 (HY000) at line 1016: MySQL server has gone away)

    今天在上班过程中需要将一个1.3G的数据库sql文件导入到mysql数据库中去,在执行过程遇到了一些问题,执行到一半时报错,错误如下 ERROR 2006 (HY000) at line 1016: ...

  4. [奇葩问题] ERROR 2013 (HY000): Lost connection to MySQL server during query

    查询一条耗时30s以上语句,实际为2分钟多. mysql> select version(); +------------+ | version() | +------------+ | 5.6 ...

  5. ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0

    最近遇到一个MySQL连接的问题,远程连接MySQL时遇到"ERROR 2013 (HY000): Lost connection to MySQL server at 'reading a ...

  6. MySQL5.1升级5.6后,执行grant出错:ERROR 2013 (HY000): Lost connection to MySQL server during query【转载】

    转载: MySQL5.5升级5.6后,执行grant出错:ERROR 2013 (HY000): Lost connection to -mysql教程-数据库-壹聚教程网http://www.111 ...

  7. mysql登陆时出现ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

    有4到5天没开mysql,这天晚上打=打开phpstudy,想进去mysql练习练习,结果丢给我这个 ERROR 2013 (HY000): Lost connection to MySQL serv ...

  8. 解决ERROR 2006 (HY000): MySQL server has gone away

    刚把博客从百度云搬到腾讯云,发现文章少了几篇.当时在导入dump数据的时候,就曾经发现mysql提示: ERROR 2006 (HY000): MySQL server has gone away N ...

  9. ERROR 2013 (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', system error: 2

    ERROR (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', system ...

随机推荐

  1. 160606、springmvc中使用Spring Mobile

    springmobile特点: 1.客户端设备识别:识别结果只有3种类型:NORMAL(非手机设备).MOBILE(手机设备).TABLET(平板电脑). 2.网站偏好设置:Spring 通过设备识别 ...

  2. Struts2中解决表单重复提交

    3. 表单的重复提交问题 1). 什么是表单的重复提交 > 在不刷新表单页面的前提下:  >> 多次点击提交按钮 >> 已经提交成功, 按 "回退" ...

  3. sersync+rsync原理及部署

    标签:sersync+rsync部署文档 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liubao0312.blog.51ct ...

  4. Browser Cookie Limits

    w https://cait.calarts.edu/hc/en-us/articles/217055138-Error-Maximum-Number-of-Cookie-Values-Reached ...

  5. 【转】通过ionice和nice降低shell脚本运行的优先级

    对于一些运行时会造成系统满载的脚本, 例如数据库备份, 会影响当时其他服务的响应速度, 可以通过ionice和nice对其IO优先级和CPU优先级进行调整例如降低"/usr/local/bi ...

  6. CF #301 E:Infinite Inversions(逆序数,树状数组)

    A-Combination Lock  B-School Marks   C-Ice Cave   D-Bad Luck Island   E-Infinite Inversions E:Infini ...

  7. Linux升级python至3.4.4

    wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz ls .tgz mkdir /usr/local/python3 cd Py ...

  8. LocalActivityManager与ActivityGroup

    Helper class for managing multiple running embedded activities in the same process. This class is no ...

  9. 012-HQL中级2-Hive如何执行文件中的sql语句

    Hive可以运行保存在文件里面的一条或多条的语句,只要用-f参数,一般情况下,保存这些Hive查询语句的文件通常用.q或者.hql后缀名,但是这不是必须的,你也可以保存你想要的后缀名.假设test文件 ...

  10. JavaScript工具库 lodash 中文文档 英文文档

    https://lodash.com/docs/    英文版 http://lodashjs.com/docs/   中文版 http://www.css88.com/doc/lodash/ 中文版 ...