• MySQL server has gone away问题得解决方案


    mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了。

    造成这样的原因一般是sql操作的时间过长,或者是传送的数据太大(例如使用insert ... values的语句过长, 这种情况可以通过修改max_allowed_packed的配置参数来避免,也可以在程序中将数据分批插入)。

    产生这个问题的原因有很多,总结下网上的分析得到一个最重要得:

    原因: Your SQL statement was too large.

    当查询的结果集超过 max_allowed_packet 也会出现这样的报错。定位方法是打出相关报错的语句。

    用select * into outfile 的方式导出到文件,查看文件大小是否超过 max_allowed_packet ,如果超过则需要调整参数,或者优化语句。

    mysql> show global variables like 'max_allowed_packet';
    +--------------------+---------+
    | Variable_name      | Value   |
    +--------------------+---------+
    | max_allowed_packet | 1048576 |
    +--------------------+---------+
    1 row in set (0.00 sec)

    修改参数:mysql> set global max_allowed_packet=1024*1024*16;

    mysql> show global variables like 'max_allowed_packet';
    +--------------------+----------+
    | Variable_name      | Value    |
    +--------------------+----------+
    | max_allowed_packet | 16777216 |
    +--------------------+----------+
    1 row in set (0.00 sec)

    ------------ 以下是网络搜索的资料 -------------------


    mysql手册上说 

    Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server. 

    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: 

    shell> mysql --max_allowed_packet=32M That sets the packet size to 32MB. 

    The server's default max_allowed_packet value is 1MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOB columns). For example, to set the variable to 16MB, start the server like this: 

    shell> mysqld --max_allowed_packet=16M You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 16MB, add the following lines in an option file: 

    [mysqld]max_allowed_packet=16M 

    使用mysql做数据库还原的时候,由于有些数据很大,会出现这样的错误:The MySQL Server returned this Error:MySQL Error Nr.2006-MySQL server has gone away。我的一个150mb的备份还原的时候就出现了这错误。解决的方法就是找到mysql安装目录,找到my.ini文件,在文件的最后添加:max_allowed_packet = 10M(也可以设置自己需要的大小)。 max_allowed_packet 参数的作用是,用来控制其通信缓冲区的最大长度。

    转载:http://www.jb51.net/article/23781.htm

    愿我们漂泊半生, 归来仍少年!
  • 相关阅读:
    16
    15
    14
    13
    12
    11
    10
    python包管理器修改镜像地址
    Linux环境下安装hadoop分布式集群+问题总结
    解剖css中的clear属性
  • 原文地址:https://www.cnblogs.com/Lonnn/p/6912907.html
Copyright © 2020-2023  润新知