使用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.
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 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错误代码查询
无论安装何版本的mysql,在管理工具的服务中启动mysql服务时都会在中途报错。内容为:在 本地计算机 无法启动mysql服务 错误1067:进程意外中止。
mysql错误处理方式,常见的错误处理方式 最全面的错误处理方式
Mysql安装错误代码对照,sql安装参照,帮助你解决安装遇到的问题
查询mysql错误信息、及js错误信息 说明
解决Navicat for MySQL 连接 Mysql 8.0.4 出现1251 Client does not support authentication protocol requested by server;consider upgrading MySQL client 错误
MySql错误码大全
比较全的mysql错误代码和消息对照表,如有未列出的额外消息,请告知,会及时更新
mysql的常见错误解决:一.在进入mysql数据库时出错;二、在创建数据库时报错。
mysql常用错误提示代码详解,方便查看对应错误
本文介绍了MySQL常见错误提示及解决方法。
MySql错误代码中文说明,排错的时候可以看看
MySQL_错误代码以及出错信息对照: 0101 属于其他进程的专用标志。 0102 标志已经设置,无法关闭。 0103 无法再次设置该标志。 0104 中断时无法请求专用标志。 0105 此标志先前的所有权已终止。 0106 请...
本文档将mysql经常出现的错误进行一个比较全面的总结,有了他你就可以很快速的查询到所写的代码出现的是什么错误了。
Mysql 安装错误的详细解决方法一览表
主要错误代码,主要讲术mySQL错误代码。 针对不同的错误 相对应不同的代码。
mysql常见错误汇总 如列别名问题,使用 DATE 列的问题,空值问题, 使用 MySQL 程序时的常见错误 1 拒绝访问 2 无法连接到[本地] MySQL服务器3 与 MySQL 服务器的连接丢失 4 以交互方式输入密码失败 5 连接过多 6 ...
MySql常见错误代码