How to fix mysql has gone away

Hi,
How to fix mysql error “[2006] MySQL server has gone away”?
My my.cnf file:

[client]
port=3306
socket=/var/run/mysqld/mysqld.sock

[mysqld_safe]
socket=/var/run/mysqld/mysqld.sock

[mysqld]
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
port=3306
basedir=/usr
datadir=/var/lib/mysql
tmpdir=/tmp
lc-messages-dir=/usr/share/mysql
log_error=/var/log/mysql/error.log
#skip-networking
bind-address = xxx

symbolic-links=0

skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 256M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

#innodb_use_native_aio = 0
innodb_file_per_table
innodb_log_file_size = 128M

max_connections=300
max_user_connections=100
wait_timeout=180
interactive_timeout=50
long_query_time=5

!includedir /etc/mysql/conf.d/

to be honest: no idea, to less informations. Basicly it sounds like you’re mysql server has gone, which has a reason that would be detectable inside your logs.

2019-12-29 21:08:32 8044 [Warning] Aborted connection 8044 to db: 'daffyy_db' user: 'daffyy_db' host: 'xxx' (Got timeout reading communication packets)
2019-12-29 21:08:32 8045 [Warning] Aborted connection 8045 to db: 'daffyy_db' user: 'daffyy_db' host: 'xxx' (Got timeout reading communication packets)
2019-12-29 21:33:25 8826 [Warning] Aborted connection 8826 to db: 'daffyy_db' user: 'daffyy_db' host: 'xxx' (Got timeout reading communication packets)

@daffyy I apologize if this sounds rude, but have you tried searching google for an answer? It sounds like maybe a connection is timing out on you.

These are some of the top results I found:
https://matomo.org/faq/troubleshooting/faq_183/

have you check my conf file before post?

The conf file looks good, otherwise I’ve wrote you about it…

PS: the log you posted is just a timeout because of your downed mysql server.What happebs if you start it again?

2019-12-29 21:33:25 8827 [Warning] Aborted connection 8827 to db: 'daffyy_db' user: 'daffyy_db' host: 'xxx' (Got timeout reading communication packets)
2019-12-29 21:55:05 9520 [Warning] Aborted connection 9520 to db: 'daffyy_db' user: 'daffyy_db' host: 'xxx' (Got timeout reading communication packets)
2019-12-29 21:55:06 9521 [Warning] Aborted connection 9521 to db: 'daffyy_db' user: 'daffyy_db' host: 'xxx' (Got timeout reading communication packets)
2019-12-29 22:09:57 0 [Note] /usr/sbin/mysqld (initiated by: unknown): Normal shutdown
2019-12-29 22:09:57 0 [Note] Event Scheduler: Purging the queue. 0 events
2019-12-29 22:09:57 0 [Note] InnoDB: FTS optimize thread exiting.
2019-12-29 22:09:57 0 [Note] InnoDB: Starting shutdown...
2019-12-29 22:09:57 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2019-12-29 22:09:57 0 [Note] InnoDB: Instance 0, restricted to 2003 pages due to innodb_buf_pool_dump_pct=25
2019-12-29 22:09:57 0 [Note] InnoDB: Buffer pool(s) dump completed at 191229 22:09:57
2019-12-29 22:09:58 0 [Note] InnoDB: Shutdown completed; log sequence number 8129845884; transaction id 2879071
2019-12-29 22:09:58 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-12-29 22:09:58 0 [Note] /usr/sbin/mysqld: Shutdown complete

2019-12-29 22:09:59 0 [Note] InnoDB: Using Linux native AIO
2019-12-29 22:09:59 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-12-29 22:09:59 0 [Note] InnoDB: Uses event mutexes
2019-12-29 22:09:59 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2019-12-29 22:09:59 0 [Note] InnoDB: Number of pools: 1
2019-12-29 22:09:59 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-12-29 22:09:59 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2019-12-29 22:09:59 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-12-29 22:09:59 0 [Note] InnoDB: Completed initialization of buffer pool
2019-12-29 22:09:59 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-12-29 22:10:01 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-12-29 22:10:01 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-12-29 22:10:01 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-12-29 22:10:01 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-12-29 22:10:01 0 [Note] InnoDB: Waiting for purge to start
2019-12-29 22:10:02 0 [Note] InnoDB: 10.4.10 started; log sequence number 8129845884; transaction id 2879069
2019-12-29 22:10:02 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-12-29 22:10:02 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-12-29 22:10:02 0 [Note] Server socket created on IP: 'xxx'.
2019-12-29 22:10:02 0 [Note] Reading of all Master_info entries succeeded
2019-12-29 22:10:02 0 [Note] Added new Master_info '' to hash table
2019-12-29 22:10:02 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.4.10-MariaDB-1:10.4.10+maria~stretch'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2019-12-29 22:10:04 0 [Note] InnoDB: Buffer pool(s) load completed at 191229 22:10:04

you’re server is ready for connections, so I can’t see any issues there. Is the mysql server back up?

No, only hestacp back up users db.
I have a server for the cs 1.6 game and it often crashes with this error.

L 12/29/2019 - 03:33:08: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 03:33:08: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 15:04:31: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 15:04:31: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 17:25:12: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 17:25:13: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 17:25:14: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 17:25:14: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:09:33: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:09:33: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:09:33: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:12:00: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:12:00: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:12:00: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:12:02: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:12:02: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:12:02: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:13:15: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:13:15: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:13:15: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:24:57: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 19:24:57: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 20:37:30: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 20:37:30: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 21:35:37: SQL Query Error. [2006] MySQL server has gone away
L 12/29/2019 - 21:35:37: SQL Query Error. [2006] MySQL server has gone away

Sometimes queries are done correctly but sometimes there is such an error.
The problem also occurred with php scripts connecting to the database remotely/local

probably whatever query is running there takes too long and simply runs into that timeout.

seems you already increased the wait_timeout, try raising the interactive_timeout as well. if that helps use long-query logging to check which request takes that long and think about optimizing the query or table structure or use of indexes etc. :wink:

2 Likes

I just wanted to add that I just ran into some similar errors in my logs today. I accidentally copied some large files to my system drive (which is very small) causing it to be 100% full. I didn’t realize it and ended up spending the last couple hours trying to troubleshoot the ‘mysql has gone away’ error only to find out that my system partition was full and it broke mariadb. So in my case the error was misleading.

Not saying this is the solution, but just something to consider.

Here is an excerpt from my notes when building a new server:
# MySQL - Increase MySQL packet size [solves the "MySQL Server gone" error]
sed -ri 's/#?max_allowed_packet\s+.*/max_allowed_packet = 512M/' /etc/mysql/my.cnf

The above command will raise the limit of the max_allowed_packet to 512MB.

Quite some time ago I run into this problem (MySQL server has gone away) and by googling around I found out that by changing this value, my problem was solved.

Of course, it all depends on the use case. Some people might not face that problem if their SQL queries are not big.