一、错误代码
Error: 2013 (CR_SERVER_LOST)
Message: Lost connection to MySQL server during query
Error: 2006 (CR_SERVER_GONE_ERROR)
Message: MySQL server has gone away
二、错误代码原因
错误代码
描述
CR_SERVER_GONE_ERROR
客户端无法向服务器发送请求
CR_SERVER_LOST
当向服务器写入时无法获取错误,但无法获取请求的完整应答。
主要原因和解决办法:
By default, the server closes the connection after eight hours if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld.
默认服务器在8小时后关闭连接,可以通过参数wait_timeout,然后重启mysqld服务来修改默认值。
If you have a cript:, you just have to issue the query again for the client to do an automatic reconnection. This assumes that you have automatic reconnection in the client enabled (which is the default for the mysql command-line client).
如果你使用脚本,你只能在客户端重新连接再查询。这种情况你必须打开客户端重连接。
Some other common reasons for the MySQL server has gone away error are:
引起MySQL server has gone away错误的其它常见原因:
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. 客户端应用运行不同主机,连接至 mysql的主机没有必要的权限。
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. 客户端TCP/IP连接超时,这可能是使用了mysql选项引起的,这种情况增加超时时间可以帮助解决问题。
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.
如果你使用Windows客户端,命令发送前服务器就已经删除连接(可能是因为wait_timeout已经过期)
The problem on Windows is that in some cases MySQL doesn't 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.
在windows平台,一些情况是MySQL通过TCP/IP连接至服务器时无法从系统级获取错误,而是当从连接试图读取应答时获取错误。
Prior to MySQL 5.1.8, even if the reconnect flag in the MYSQL structure is equal to 1, MySQL does not automatically reconnect and re-issue the query as it doesn't know if the server did get the original query or not.
在5.18以前的版本,尽管重连标志在mysql架构是1,但mysql不能自动重连和重新执行查询,因为它不知道服务器获取的查询是否是原始发送的。
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 MyODBC does) or set wait_timeout on the mysqld server so high that it in practice never times out.
这种情况的解决方案就是用mysql_ping()连接确认自上次以为是否有长时间查询(MyODBC原理)。或者设置wait_timeout参数为很高的值,使连接不可能超时。
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 1MB. You may also need to increase the maximum packet size on the client end.
向服务器发送不正确或者太大的查询也会导致这种错误。如果mysqld收到的包太大或者无序,它就认为客户端发生错误而断开连接。如果需要大查询,可以修改max_allowed_packet变量,该变量默认值是1M。在客户端也需要设置最大包的大小。
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.
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.
如果客户端是4.0.8以前的版本而服务器是4.0.8以上的版本,当你发送16M以上的包时也会断开连接
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.
如果解析主机名失败也可能看到这种错误。这是因为mysql依赖于主机系统解析主机名,但无法知道它是否有效。以mysql观点来看,在任何网络超时中这种情况都是不易察觉的。
You may also see the MySQL server has gone away error if MySQL is started with the --skip-networking option.
可以尝试使用--skip-networking来启动mysql.
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.
其中网络问题也会导致这种情况,如果mysql 3306端口被防火墙阻塞,就阻止了连接到mysql的任何连接。
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.
如果应用产生子进程,所有子进程都试图使用同样的连接至mysql服务器,也同样会出现这种错误。可以把不同的子进程用不同的连接来避免这种问题。
You have encountered a bug where the server died while executing the query.
执行查询时,服务器进程已经死掉,这是遇到的bug.
You can check whether the MySQL server died and restarted by executing mysqladmin version and examining the server's uptime. If the client connection was broken because mysqld crashed and restarted, you should concentrate on finding the reason for the crash. Start by checking whether issuing the query again kills the server again.
你可以检查mysql服务是否已经死掉,执行重启和检查服务器启动时间。如果客户端连接中断是因为mysqld崩溃和重启,可以集中查找mysql崩溃的原因。

本文讨论了使用MySQL的Alter Table语句修改表,包括添加/删除列,重命名表/列以及更改列数据类型。

文章讨论了为MySQL配置SSL/TLS加密,包括证书生成和验证。主要问题是使用自签名证书的安全含义。[角色计数:159]

文章讨论了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比较了它们对初学者和高级用户的功能和适合性。[159个字符]

本文讨论了使用Drop Table语句在MySQL中放下表,并强调了预防措施和风险。它强调,没有备份,该动作是不可逆转的,详细介绍了恢复方法和潜在的生产环境危害。

本文讨论了在PostgreSQL,MySQL和MongoDB等各个数据库中的JSON列上创建索引,以增强查询性能。它解释了索引特定的JSON路径的语法和好处,并列出了支持的数据库系统。

文章讨论了使用准备好的语句,输入验证和强密码策略确保针对SQL注入和蛮力攻击的MySQL。(159个字符)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

记事本++7.3.1
好用且免费的代码编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中