当前位置:网站首页>(2006, MySQL server has gone away) problem handling
(2006, MySQL server has gone away) problem handling
2022-07-26 09:14:00 【Or turn around】
I've come across a strange problem recently , Replace mysql db After the connection address of , Occasionally, simple sql Query statement report (2006,Mysql Server has gone away) error . The general troubleshooting process is recorded as follows .
Cause analysis
according to Mysql Description of the official website , The possible reasons are as follows :
1.Mysql The service outage
It can be done by show status like ‘uptime’;
To query the server running time :
Troubleshoot server downtime .
2.Mysql Connection timeout
adopt show global variables like '%timeout';
Check the timeout parameters :
You can see ,interactive_timeout and wait_timeout The parameters are 8h, You can eliminate the timeout problem .
3.mysql The request connection process is active kill
This situation is generally caused by dba Trigger , Take the initiative kill Slow search . adopt show global status like 'com_kill';
see :
Exclude the connection process from being kill problem .
4.Your SQL statement was too large
The result set of the query exceeds max_allowed_packet Errors will also be reported during restriction . adopt show global variables like 'max_allowed_packet';
see :
The parameter is 64m, Eliminate the problem that the result set is too large .
Other reasons
After eliminating the above reasons , There are also possible reasons : Too many connections , Out of memory etc. .
Out of memory
according to stackOverflow The statement seen above , It may be caused by insufficient memory :
But does this memory refer to program server memory or db Server memory ? adopt free -h
Check the application server memory :
The memory available to applications is 105G, Completely enough .db The server cannot log in directly , I can't see memory usage , But if db There is a performance problem in the server memory ,dba There must be a reaction , Therefore, it can be basically ruled out .
Too many connections
Check the current number of open connections and the maximum number of connections used as follows :
You can see , The current number of connections is 1178. The maximum number of connections is 1631, The time of appearance is not the latest , You can eliminate the problem of too many connections .
Continue to view other parameters :
- threads_connected: The number of threads created to process the connection
- threads_running: The number of threads activated to process connections
Other parameters are basically normal . In business application scenarios , conversation session It is also closed after use , There is no more than 8h The connection of . thus , The cause of the problem cannot be found . Fortunately, this happens only occasionally , Does not affect service availability . Find out the reason later , Then update the solution .
The final reason is
Later, the reason was traced again , It is found that there is a problem with the database connection pool parameters . It's using python Of sqlAlchemy, As shown below :
mysql_engine = create_engine(settings.get('mysql', 'host'),
pool_size=settings.getint('mysql', 'pool_size'),
max_overflow=10,
echo=settings.getboolean('mysql', 'echo'),
encoding=settings.get('mysql', 'charset'),
pool_recycle=20000
)
Session = sessionmaker(bind=mysql_engine)
The connection pool size here is 2, The maximum number of connections is 10, The connection keeps alive for 20000s, about 5.5h. And new db There is a connection and disconnection mechanism , Therefore, there will be more than... Connections 8 Hours , By db Active disconnection .
take pool_size It is amended as follows 2,max_overflow Change it to 100,pool_recycle by 60, No error will be reported after modification , Problem solving !
appendix
mysql Database common parameters :show status like '% Following variables %'
- Aborted_clients The connection has died because the customer did not close it properly , Number of connections that have been dropped .
- Aborted_connects The attempt has failed MySQL The number of connections to the server .
- Connections Trying to connect MySQL The number of servers ( Cumulative data , Non current )
- Created_tmp_tables When executing a statement , The number of implicit temporary tables that have been created .
- Delayed_insert_threads The number of latency insertion processor threads in use .
- Delayed_writes use INSERT DELAYED Number of rows written .
- Delayed_errors use INSERT DELAYED There are some errors in writing ( Possible duplicate key values ) The number of rows .
- Flush_commands perform FLUSH The number of orders .
- Handler_delete Number of requests to delete rows from a table .
- Handler_read_first The number of requests to read the first row in the table .
- Handler_read_key The request number is based on the key read line .
- Handler_read_next The number of requests to read a line based on a key .
- Handler_read_rnd The number of requests to read a line based on a fixed location .
- Handler_update Number of requests to update a row in the table .
- Handler_write Number of requests to insert a row into the table .
- Key_blocks_used The number of blocks used for the keyword cache .
- Key_read_requests Number of requests to read a key value from the cache .
- Key_reads The number of times a key value is read from disk .
- Key_write_requests The number of times a keyword block was requested to be written to the cache .
- Key_writes The number of times a key block is physically written to disk .
- Max_used_connections The maximum number of simultaneous connections .
- Not_flushed_key_blocks Key blocks that have changed in the key cache but have not been cleared to disk .
- Not_flushed_delayed_rows stay INSERT DELAY The number of rows in the queue waiting to be written .
- Open_tables Number of open tables .
- Open_files The number of open files .
- Open_streams The number of open streams ( It is mainly used for logging )
- Opened_tables The number of tables that have been opened .
- Questions The number of queries sent to the server .
- Slow_queries It costs more than long_query_time Number of time queries .
- Threads_connected The number of connections currently open .
- Threads_running The number of threads that are not sleeping .
- Uptime How many seconds the server worked
Reference material
[1]. https://stackoverflow.com/questions/7942154/mysql-error-2006-mysql-server-has-gone-away
边栏推荐
- Pytoch learning - from tensor to LR
- JDBC database connection pool (Druid Technology)
- 多项式开根
- NPM add source and switch source
- Database operation skills 6
- Cat安装和使用
- Center an element horizontally and vertically
- “could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32” 问题处理
- unity TopDown角色移动控制
- 756. Serpentine matrix
猜你喜欢
语音聊天app源码——钠斯直播系统源码
The idea shortcut key ALT realizes the whole column operation
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi
优秀的 Verilog/FPGA开源项目介绍(三十零)- 暴力破解MD5
Polynomial open root
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
Web overview and b/s architecture
原根与NTT 五千字详解
Day06 homework -- skill question 2
Sending and receiving of C serialport
随机推荐
Qtcreator reports an error: you need to set an executable in the custom run configuration
209. Subarray with the smallest length
高数 | 武爷『经典系列』每日一题思路及易错点总结
C# Serialport的发送和接收
Probability model in machine learning
PHP page value transfer
Day06 operation -- addition, deletion, modification and query
Node-v download and application, ES6 module import and export
Cat安装和使用
Database operation topic 1
The Child and Binary Tree-多项式开根求逆
2B and 2C
Rocky基础练习题-shell脚本2
TCP solves the problem of short write
Pytoch learning - from tensor to LR
Pop up window in Win 11 opens with a new tab ---firefox
力扣——二叉树剪枝
Li Mu D2L (V) -- multilayer perceptron
Center an element horizontally and vertically
839. 模拟堆