關(guān)于網(wǎng)站程序安裝過(guò)程中出現(xiàn)mysql提示2006和2013錯(cuò)誤代碼
官方關(guān)于2013和2006錯(cuò)誤代碼產(chǎn)生原因和解決方案
一、錯(cuò)誤代碼
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
二、錯(cuò)誤代碼原因
錯(cuò)誤代碼
描述
CR_SERVER_GONE_ERROR
客戶端無(wú)法向服務(wù)器發(fā)送請(qǐng)求
CR_SERVER_LOST
當(dāng)向服務(wù)器寫入時(shí)無(wú)法獲取錯(cuò)誤,但無(wú)法獲取請(qǐng)求的完整應(yīng)答。
主要原因和解決辦法:
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.
默認(rèn)服務(wù)器在8小時(shí)后關(guān)閉連接,可以通過(guò)參數(shù)wait_timeout,然后重啟mysqld服務(wù)來(lái)修改默認(rèn)值。
If you have a script, 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).
如果你使用腳本,你只能在客戶端重新連接再查詢。這種情況你必須打開(kāi)客戶端重連接。
Some other common reasons for the MySQL server has gone away error are:
引起MySQL server has gone away錯(cuò)誤的其它常見(jiàn)原因:
You (or the db administrator) has killed the running thread with a KILL statement or a mysqladmin kill command. 人為殺掉查詢進(jìn)程。
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. 服務(wù)器關(guān)閉連接后,試圖向服務(wù)器發(fā)送查詢,這表明必須修改應(yīng)用邏輯錯(cuò)誤。
A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host. 客戶端應(yīng)用運(yùn)行不同主機(jī),連接至 mysql的主機(jī)沒(méi)有必要的權(quán)限。
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連接超時(shí),這可能是使用了mysql選項(xiàng)引起的,這種情況增加超時(shí)時(shí)間可以幫助解決問(wèn)題。
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). 服務(wù)器端連接超時(shí)和客戶端自動(dòng)重連被關(guān)閉
You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.
如果你使用Windows客戶端,命令發(fā)送前服務(wù)器就已經(jīng)刪除連接(可能是因?yàn)?/SPAN>wait_timeout已經(jīng)過(guò)期)
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平臺(tái),一些情況是MySQL通過(guò)TCP/IP連接至服務(wù)器時(shí)無(wú)法從系統(tǒng)級(jí)獲取錯(cuò)誤,而是當(dāng)從連接試圖讀取應(yīng)答時(shí)獲取錯(cuò)誤。
Prior to MySQL
在5.18以前的版本,盡管重連標(biāo)志在mysql架構(gòu)是1,但mysql不能自動(dòng)重連和重新執(zhí)行查詢,因?yàn)樗恢婪⻊?wù)器獲取的查詢是否是原始發(fā)送的。
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()連接確認(rèn)自上次以為是否有長(zhǎng)時(shí)間查詢(MyODBC原理);蛘咴O(shè)置wait_timeout參數(shù)為很高的值,使連接不可能超時(shí)。
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.
向服務(wù)器發(fā)送不正確或者太大的查詢也會(huì)導(dǎo)致這種錯(cuò)誤。如果mysqld收到的包太大或者無(wú)序,它就認(rèn)為客戶端發(fā)生錯(cuò)誤而斷開(kāi)連接。如果需要大查詢,可以修改max_allowed_packet變量,該變量默認(rèn)值是
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語(yǔ)句插入大量的行也會(huì)引起這種錯(cuò)誤。這些語(yǔ)句不考慮插入的行數(shù)而發(fā)送單一的請(qǐng)求至服務(wù)器。因此,減少插入的行數(shù)可以避免經(jīng)常發(fā)生這種錯(cuò)誤。
You also get a lost connection if you are sending a packet 16MB or larger if your client is older than
如果客戶端是
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.
如果解析主機(jī)名失敗也可能看到這種錯(cuò)誤。這是因?yàn)?/SPAN>mysql依賴于主機(jī)系統(tǒng)解析主機(jī)名,但無(wú)法知道它是否有效。以mysql觀點(diǎn)來(lái)看,在任何網(wǎng)絡(luò)超時(shí)中這種情況都是不易察覺(jué)的。
You may also see the MySQL server has gone away error if MySQL is started with the --skip-networking option.
可以嘗試使用--skip-networking來(lái)啟動(dòng)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.
其中網(wǎng)絡(luò)問(wèn)題也會(huì)導(dǎo)致這種情況,如果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.
如果應(yīng)用產(chǎn)生子進(jìn)程,所有子進(jìn)程都試圖使用同樣的連接至mysql服務(wù)器,也同樣會(huì)出現(xiàn)這種錯(cuò)誤?梢园巡煌淖舆M(jìn)程用不同的連接來(lái)避免這種問(wèn)題。
You have encountered a bug where the server died while executing the query.
執(zhí)行查詢時(shí),服務(wù)器進(jìn)程已經(jīng)死掉,這是遇到的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服務(wù)是否已經(jīng)死掉,執(zhí)行重啟和檢查服務(wù)器啟動(dòng)時(shí)間。如果客戶端連接中斷是因?yàn)?/SPAN>mysqld崩潰和重啟,可以集中查找mysql崩潰的原因。