`

mysql 2006 错误

阅读更多

使用libmysqlclient出现core,日志显示

mysql 遇到2013 ,2006错误(MySQL server has gone away)

core文件信息如下:

 

(gdb) bt
#0  0x000000000051eb12 in my_real_read (net=0x7fc8e80009e0, complen=0x7fc9ce1fb438) at /opt/mysql-5.5.41/sql/net_serv.cc:839
#1  0x000000000051eed5 in my_net_read (net=0x7fc8e80009e0) at /opt/mysql-5.5.41/sql/net_serv.cc:1034
#2  0x00000000005081aa in cli_safe_read (mysql=0x7fc8e80009e0) at /opt/mysql-5.5.41/sql-common/client.c:735
#3  0x00000000005088b2 in cli_read_query_result (mysql=0x7fc8e80009e0) at /opt/mysql-5.5.41/sql-common/client.c:3837
#4  0x000000000050622c in mysql_real_query (mysql=0x7fc8e80009e0, query=<value optimized out>, length=<value optimized out>)
    at /opt/mysql-5.5.41/sql-common/client.c:3924

 

(gdb) p *net
$10 = {vio = 0x0, buff = 0x0, buff_end = 0x7fc8e80071a0 "\020b", write_pos = 0x7fc8e80051a0 "\n", read_pos = 0x7fc8e80051a0 "\n", fd = 43, 
  remain_in_buf = 0, length = 0, buf_length = 0, where_b = 0, max_packet = 8192, max_packet_size = 1073741824, pkt_nr = 2, compress_pkt_nr = 2, 
  write_timeout = 31536000, read_timeout = 31536000, retry_count = 1, fcntl = 0, return_status = 0x0, reading_or_writing = 0 '\000', 
  save_char = 0 '\000', unused1 = 0 '\000', unused2 = 0 '\000', compress = 0 '\000', unused3 = 0 '\000', unused = 0x0, last_errno = 2006, 
  error = 0 '\000', unused4 = 0 '\000', unused5 = 0 '\000', 
  last_error = "MySQL server has gone away\000rver during query", '\000' <repeats 467 times>, sqlstate = "HY000", extension = 0x0}

 

 

上面NET->vio指针为NULL,因此出core,这个vio是用于vector io的。

解决办法:

http://dev.mysql.com/doc/refman/5.6/en/gone-away.html 写道
Some other common reasons for the MySQL server has gone away error are:

You (or the db administrator) has killed the running thread with a KILL statement or a mysqladmin kill command.

You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.

A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.

You got a timeout from the TCP/IP connection on the client side. This may happen if you have been using the commands: mysql_options(..., MYSQL_OPT_READ_TIMEOUT,...) or mysql_options(..., MYSQL_OPT_WRITE_TIMEOUT,...). In this case increasing the timeout may help solve the problem.
即相应mysql变量中设置NET_READ_TIMEOUT,NET_WRITE_TIMEOUT(如:SET GLOBAL NET_READ_TIMEOUT=600)
You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).

You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.
即相应mysql变量中设置WAIT_TIME_OUT (如:SET GLOBAL WAIT_TIMEOUT= 86400)
The problem on Windows is that in some cases MySQL does not get an error from the OS when writing to the TCP/IP connection to the server, but instead gets the error when trying to read the answer from the connection.

The solution to this is to either do a mysql_ping() on the connection if there has been a long time since the last query (this is what Connector/ODBC does) or set wait_timeout on the mysqld server so high that it in practice never times out.

You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 4MB (1MB before MySQL 5.6.6). You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.5.2.10, “Packet Too Large”.

An INSERT or REPLACE statement that inserts a great many rows can also cause these sorts of errors. Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, you can often avoid the error by reducing the number of rows sent per INSERT or REPLACE.

You also get a lost connection if you are sending a packet 16MB or larger if your client is older than 4.0.8 and your server is 4.0.8 and above, or the other way around.

It is also possible to see this error if host name lookups fail (for example, if the DNS server on which your server or network relies goes down). This is because MySQL is dependent on the host system for name resolution, but has no way of knowing whether it is working—from MySQL's point of view the problem is indistinguishable from any other network timeout.

You may also see the MySQL server has gone away error if MySQL is started with the --skip-networking option.

Another networking issue that can cause this error occurs if the MySQL port (default 3306) is blocked by your firewall, thus preventing any connections at all to the MySQL server.

You can also encounter this error with applications that fork child processes, all of which try to use the same connection to the MySQL server. This can be avoided by using a separate connection for each child process.

You have encountered a bug where the server died while executing the query.

但 采用官方的说法,未能解决问题。还是在程序中进行判断,至少避免core dump错误:

int err = mysql_errorno(mysql_con);
if(mysql_con && err==2006 && err == 2013)
        {
            mysql_close(mysql_con);
            mysql_con =NULL;
        }
//TODO: Reconnet to mysql

 

  • 给mysql连接,添加自动连接,问题再没有发生。发生这种故障,有可能是超时断了连接。设置方式:
  •         my_bool my_true= TRUE;
            mysql_options(mysql_con, MYSQL_OPT_RECONNECT, &my_true);
     另外,可以结合mysql_ping。如果发现已经端口,再重新连接。
    int err_code = mysql_ping(mysql_con);
     

 

分享到:
评论

相关推荐

    MySQL导入sql脚本错误:2006 解决方法

    MySQL导入sql脚本错误:2006 – MySQL server has gone away 到如一些小脚本很少报错,但最近导入一个10+M的SQL脚本,却重复报错: Error occured at:2014-03-24 11:42:24 Line no.:85 Error Code: 2006 - MySQL ...

    MySql常见错误表

    这个文本里记载了很多mysql的错误信息以及编号..可以方便的指导数据库报了什么样的错误

    Mysql安装错误代码对照

    ### MySQL安装错误代码详解 #### 1016 错误:文件无法打开 当遇到“文件无法打开”错误(1016)时,这通常意味着MySQL在尝试访问某个文件时遇到了问题。可能的原因包括文件损坏、权限问题或者文件路径配置错误。...

    MySQL错误代码查询

    本篇文章将详细探讨MySQL错误代码及其含义,帮助你更好地理解和解决遇到的问题。 首先,MySQL错误代码是一个三位数字,例如“1048”,它代表了特定的错误情况。错误代码后面可能还会跟着一个简短的英文描述,提供更...

    查询mysql错误信息、及js错误信息

    本文将详细讲解如何查询MySQL错误信息以及JavaScript错误信息,并提供相关知识点。 首先,我们来了解一下如何查询MySQL错误信息。MySQL在执行SQL语句时,如果遇到语法错误、权限问题或逻辑错误等,会返回一个错误...

    mysql的常见错误解决

    MySQL 的常见错误解决 MySQL 是一个广泛使用的关系数据库管理系统,但是在使用过程中经常会遇到各种错误,本文将介绍 MySQL 的常见错误解决方案。 一、在进入 MySQL 数据库时出错 在使用 MySQL 客户端连接数据库...

    Mysql服务无法启动的1067错误解决

    ### MySQL服务无法启动的1067错误解决 在日常使用MySQL的过程中,用户可能会遇到一个常见问题:在尝试启动MySQL服务时出现“错误1067:进程意外中止”的提示。这一问题不仅困扰着初学者,对于有一定经验的开发者来...

    MySql错误代码中文说明

    本文将详细介绍MySQL错误代码及其中文说明,以帮助您在排错时更有效地定位问题。 MySQL的错误代码由三位数字组成,如“1048”,这些代码通常在错误消息中出现,伴随着关于错误的简短描述。错误代码的前两位数字大致...

    mysql错误以及处理方式

    mysql错误处理方式,常见的错误处理方式 最全面的错误处理方式

    MySql 1067错误解决方法

    ### MySql 1067错误解决方法 在日常使用MySQL数据库的过程中,我们经常会遇到各种各样的问题,其中“1067错误”是较为常见的一种系统级别的错误提示。本篇文章将详细阐述MySQL 1067错误的具体含义、常见的触发场景...

    Mysql错误代码大全 中文

    总之,“Mysql错误代码大全 中文”是一份宝贵的资源,它将帮助开发者在遇到MySQL错误时迅速定位问题,提升工作效率,是每个MySQL使用者不可或缺的工具。无论是初学者还是经验丰富的开发者,都应该熟悉这些错误代码,...

    MYSQL_root密码错误

    该问题的出现可能是由于用户修改了MYSQL数据库的root密码,但是在连接MYSQL时却出现了“access denied for user 'root'@'localhost'”的错误信息。这种错误的出现可能是由于MYSQL的bin目录没有加入到PATH路径中所...

    mysql错误码大全

    比较全的mysql错误代码和消息对照表,如有未列出的额外消息,请告知,会及时更新

    mysql连接错误解决

    ### MySQL连接错误解决 在安装MySQL之后,可能会遇到无法连接的问题,其中一种常见的错误提示是“Error 1045 Access denied for user 'root'@'localhost' (using password: YES)”。这个问题通常出现在尝试使用root...

    Mysql安装错误 解决方法

    本文将详细解析在安装MySQL时可能遇到的两种常见错误——Error Nr.2003和Error Nr.1045,并提供相应的解决策略。 ### Error Nr.2003:无法连接到MySQL服务器 #### 错误信息: &gt; Can't connect to MySQL server on...

    Oracle+MySQl错误代码解析大全

    "Oracle+MySQL错误代码解析大全"提供了一个宝贵的资源,帮助数据库管理员和开发人员迅速识别并解决这些错误。 Oracle数据库的错误代码通常以数字形式出现,如ORA-00001到ORA-65313。每个错误代码都有其特定的含义,...

    mysql常用错误提示代码详解

    mysql常用错误提示代码详解,方便查看对应错误

    mysql8.0旧客户端连接报1251错误

    本文主要针对"mysql8.0旧客户端连接报1251错误"这一常见问题进行深入解析,并提供解决方案。 MySQL 8.0是一个重大更新,引入了许多新特性和安全改进。其中一项变化就是密码验证插件的改变。在MySQL 8.0之前,系统...

    大牛总结 MySql常见错误集锦

    在使用MySQL的过程中,开发者可能会遇到各种错误,这些错误可能是由于语法错误、配置问题、权限限制或是其他原因引起的。本篇文章将深入探讨由大牛总结的MySQL常见错误,并提供解决策略。 1. 错误1045: Access ...

    mysql错误代码大全

    本文档将mysql经常出现的错误进行一个比较全面的总结,有了他你就可以很快速的查询到所写的代码出现的是什么错误了。

Global site tag (gtag.js) - Google Analytics