Azure Database for MySQL server has gone away

Published 03-13-2019 07:34 PM 4,771 Views
Microsoft
First published on MSDN on Nov 20, 2018
One of the common MySQL server errors is “MySQL server has gone away”.
This is a pretty generic error and can happen because of a server error or a client-side error. While Azure has automated bots which are used to detect and address server side issues, this tutorial will discuss client-side issues that can cause this error.

Ask yourself If this issue is happening consistently or intermittently first. If it is happening constantly look at the first part of this guide but If it is happening intermittently please jump to the second part for some common reasons for that error.



Part 1: Constantly seeing "MySQL server has gone away" error

a) Old or outdated driver:

Microsoft recommends you to connect to Azure Database for MySQL using the latest client version for your application. Check the documentation for the driver that you are using to find the latest version.

Under "Connect & Query" section of the below documentation are a few popular connectors with instructions on how to install the driver and how to connect.
https://docs.microsoft.com/en-us/azure/mysql/

MySQL documentation also lists connectors for using MySQL with applications and tools that are compatible with industry standards ODBC and JDBC. Any system that works with ODBC or JDBC can use Azure Database for MySQL.
https://dev.mysql.com/downloads/connector/

b) init_connect improperly configured

Avoid using this parameter as it can cause this error but, if necessary, ensure that you have the correct format for the argument as this parameter has different possibilities for the argument. That’s why it is not validated at the portal level and should be validated by the user.

For Example: Setting the parameter init­_connect for the following values will cause an error.
“set tmp_table_size=512M; set max_heap_table_size=512M”.


To fix this issue, set the correct arguments as a full length data sizes for the parameter. It is mandatory here and the right syntax will be as the following:
“set tmp_table_size=536870912; set max_heap_table_size=536870912”.

c) Privilege issue

A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host. Please make sure you white listed you application IP address in the Azure Database for MySQL Firewall.
https://docs.microsoft.com/en-us/azure/mysql/concepts-firewall-rules



Part 2: intermittently seeing "MySQL server has gone away" error

a) Server dropped an incorrect or too large packet

Please increase the value for “max_allowed_packet” from the Azure Database for MySQL server parameter pane to avoid issues due to the size of the packet.


b) Timeout
You got a timeout from the TCP/IP connection on the client side. Please note that there are a number of parameters that can cause this timeout to happen. After the server waits for activity to happen, a number of seconds before it closes the connection, all these parameters can be edited from the Azure MySQL server parameters pane as the following.


c) Killing a running process
DBA killed the running thread with a KILL statement or a mysqladmin kill

d) Already Closed connection with the database

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.



Reference:

https://dev.mysql.com/doc/refman/5.7/en/gone-away.html
%3CLINGO-SUB%20id%3D%22lingo-sub-369138%22%20slang%3D%22en-US%22%3EAzure%20Database%20for%20MySQL%20server%20has%20gone%20away%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369138%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Nov%2020%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20One%20of%20the%20common%20MySQL%20server%20errors%20is%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D.%20%3CBR%20%2F%3E%20This%20is%20a%20pretty%20generic%20error%20and%20can%20happen%20because%20of%20a%20server%20error%20or%20a%20client-side%20error.%20While%20Azure%20has%20automated%20bots%20which%20are%20used%20to%20detect%20and%20address%20server%20side%20issues%2C%20this%20tutorial%20will%20discuss%20client-side%20issues%20that%20can%20cause%20this%20error.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Ask%20yourself%20If%20this%20issue%20is%20happening%20consistently%20or%20intermittently%20first.%20If%20it%20is%20happening%20constantly%20look%20at%20the%20first%20part%20of%20this%20guide%20but%20If%20it%20is%20happening%20intermittently%20please%20jump%20to%20the%20second%20part%20for%20some%20common%20reasons%20for%20that%20error.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3EPart%201%3A%20Constantly%20seeing%20%22MySQL%20server%20has%20gone%20away%22%20error%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20a)%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20Old%20or%20outdated%20driver%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Microsoft%20recommends%20you%20to%20connect%20to%26nbsp%3BAzure%20Database%20for%20MySQL%20using%20the%20latest%20client%20version%20for%20your%20application.%20Check%20the%20documentation%20for%20the%20driver%20that%20you%20are%20using%20to%20find%20the%20latest%20version.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Under%20%22Connect%20%26amp%3B%20Query%22%20section%20of%20the%20below%20documentation%20are%20a%20few%20popular%20connectors%20with%20instructions%20on%20how%20to%20install%20the%20driver%20and%20how%20to%20connect.%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2F%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20MySQL%20documentation%20also%20lists%20connectors%20for%20using%20MySQL%20with%20applications%20and%20tools%20that%20are%20compatible%20with%20industry%20standards%20ODBC%20and%20JDBC.%20Any%20system%20that%20works%20with%20ODBC%20or%20JDBC%20can%20use%20Azure%20Database%20for%20MySQL.%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fconnector%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdev.mysql.com%2Fdownloads%2Fconnector%2F%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20b)%20init_connect%20improperly%20configured%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Avoid%20using%20this%20parameter%20as%20it%20can%20cause%20this%20error%20but%2C%20if%20necessary%2C%20ensure%20that%20you%20have%20the%20correct%20format%20for%20the%20argument%20as%20this%20parameter%20has%20different%20possibilities%20for%20the%20argument.%20That%E2%80%99s%20why%20it%20is%20not%20validated%20at%20the%20portal%20level%20and%20should%20be%20validated%20by%20the%20user.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20For%20Example%3A%20Setting%20the%20parameter%20init%C2%AD_connect%20for%20the%20following%20values%20will%20cause%20an%20error.%20%3CBR%20%2F%3E%20%E2%80%9Cset%20tmp_table_size%3D512M%3B%20set%20max_heap_table_size%3D512M%E2%80%9D.%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89087i7F404160E48D5214%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20To%20fix%20this%20issue%2C%20set%20the%20correct%20arguments%20as%20a%20full%20length%20data%20sizes%20for%20the%20parameter.%20It%20is%20mandatory%20here%20and%20the%20right%20syntax%20will%20be%20as%20the%20following%3A%20%3CBR%20%2F%3E%20%E2%80%9Cset%20tmp_table_size%3D536870912%3B%20set%20max_heap_table_size%3D536870912%E2%80%9D.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3Ec)%20Privilege%20issue%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20A%20client%20application%20running%20on%20a%20different%20host%20does%20not%20have%20the%20necessary%20privileges%20to%20connect%20to%20the%20MySQL%20server%20from%20that%20host.%20Please%20make%20sure%20you%20white%20listed%20you%20application%20IP%20address%20in%20the%20Azure%20Database%20for%20MySQL%20Firewall.%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fconcepts-firewall-rules%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fconcepts-firewall-rules%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20Part%202%3A%20intermittently%20seeing%20%22MySQL%20server%20has%20gone%20away%22%20error%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20a)%20Server%20dropped%20an%20incorrect%20or%20too%20large%20packet%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Please%20increase%20the%20value%20for%20%E2%80%9Cmax_allowed_packet%E2%80%9D%20from%20the%20Azure%20Database%20for%20MySQL%20server%20parameter%20pane%20to%20avoid%20issues%20due%20to%20the%20size%20of%20the%20packet.%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89088i9B5309D52040FD12%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3Eb)%20Timeout%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20You%20got%20a%20timeout%20from%20the%20TCP%2FIP%20connection%20on%20the%20client%20side.%20Please%20note%20that%20there%20are%20a%20number%20of%20parameters%20that%20can%20cause%20this%20timeout%20to%20happen.%20After%20the%20server%20waits%20for%20activity%20to%20happen%2C%20a%20number%20of%20seconds%20before%20it%20closes%20the%20connection%2C%20all%20these%20parameters%20can%20be%20edited%20from%20the%20Azure%20MySQL%20server%20parameters%20pane%20as%20the%20following.%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89089i537DAE5A26F8C434%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3Ec)%20Killing%20a%20running%20process%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20DBA%20killed%20the%20running%20thread%20with%20a%20%3CA%20href%3D%22https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Fkill.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20KILL%20%3C%2FA%3E%20statement%20or%20a%20%3CSTRONG%3E%20%3CSTRONG%3E%20%3CA%20href%3D%22https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Fmysqladmin.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20mysqladmin%20kill%20%3C%2FA%3E%20%3C%2FSTRONG%3E%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20d)%20Already%20Closed%20connection%20with%20the%20database%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20tried%20to%20run%20a%20query%20after%20closing%20the%20connection%20to%20the%20server.%20This%20indicates%20a%20logic%20error%20in%20the%20application%20that%20should%20be%20corrected.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Reference%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Fgone-away.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Fgone-away.html%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-369138%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Nov%2020%2C%202018%20One%20of%20the%20common%20MySQL%20server%20errors%20is%20%E2%80%9CMySQL%20server%20has%20gone%20away%E2%80%9D.%3C%2FLINGO-TEASER%3E
Version history
Last update:
‎Mar 13 2019 07:34 PM
Updated by: