@pcdesign

Как бороться с ошибкой: «sqlalchemy.exc.InterfaceError: (InterfaceError) 2013: Lost connection to MySQL»?

Есть сайт на flask.
Изредка, примерно 1 раз в два дня возникают такие ошибки.
sqlalchemy.exc.InterfaceError: (InterfaceError) 2013: Lost connection to MySQL server during query 'SELECT


Происходит это, я так понимаю, когда MySQL рестартует по каким-то причинам.

В логе mysql:
150312 14:20:22 [Note] /usr/libexec/mysqld: Normal shutdown

150312 14:20:22 [Note] Event Scheduler: Purging the queue. 0 events
150312 14:20:22  InnoDB: Starting shutdown...
150312 14:20:23  InnoDB: Shutdown completed; log sequence number 13754751080
150312 14:20:23 [Note] /usr/libexec/mysqld: Shutdown complete

150312 14:20:23 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
150312 14:20:41 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150312 14:20:41 InnoDB: The InnoDB memory heap is disabled
150312 14:20:41 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150312 14:20:41 InnoDB: Compressed tables use zlib 1.2.7
150312 14:20:41 InnoDB: Using Linux native AIO
150312 14:20:41 InnoDB: Initializing buffer pool, size = 128.0M
150312 14:20:41 InnoDB: Completed initialization of buffer pool
150312 14:20:41 InnoDB: highest supported file format is Barracuda.
150312 14:20:42  InnoDB: Waiting for the background threads to start
150312 14:20:43 Percona XtraDB (http://www.percona.com) 5.5.40-MariaDB-36.1 started; log sequence number 13754751080
150312 14:20:43 [Note] Plugin 'FEEDBACK' is disabled.
150312 14:20:43 [Note] Server socket created on IP: '0.0.0.0'.
150312 14:20:43 [Note] Event Scheduler: Loaded 0 events
150312 14:20:43 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.40-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
150323 15:14:18 [Note] /usr/libexec/mysqld: Normal shutdown

150323 15:14:18 [Note] Event Scheduler: Purging the queue. 0 events
150323 15:14:18  InnoDB: Starting shutdown...
150323 15:14:18  InnoDB: Waiting for 16 pages to be flushed
150323 15:14:18  InnoDB: Shutdown completed; log sequence number 14011502490
150323 15:14:18 [Note] /usr/libexec/mysqld: Shutdown complete

150323 15:14:18 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
150323 15:14:19 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150323 15:14:19 InnoDB: The InnoDB memory heap is disabled
150323 15:14:19 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150323 15:14:19 InnoDB: Compressed tables use zlib 1.2.7
150323 15:14:19 InnoDB: Using Linux native AIO
150323 15:14:19 InnoDB: Initializing buffer pool, size = 128.0M
150323 15:14:19 InnoDB: Completed initialization of buffer pool
150323 15:14:19 InnoDB: highest supported file format is Barracuda.
150323 15:14:19  InnoDB: Waiting for the background threads to start
150323 15:14:20 Percona XtraDB (http://www.percona.com) 5.5.40-MariaDB-36.1 started; log sequence number 14011502490
150323 15:14:20 [Note] Plugin 'FEEDBACK' is disabled.
150323 15:14:20 [Note] Server socket created on IP: '0.0.0.0'.
150323 15:14:20 [Note] Event Scheduler: Loaded 0 events
150323 15:14:20 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.40-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
150414 15:47:49 [Note] /usr/libexec/mysqld: Normal shutdown

150414 15:47:49 [Note] Event Scheduler: Purging the queue. 0 events
150414 15:47:50  InnoDB: Starting shutdown...
150414 15:47:50  InnoDB: Shutdown completed; log sequence number 14440827849
150414 15:47:50 [Note] /usr/libexec/mysqld: Shutdown complete

150414 15:47:50 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
150414 15:47:51 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150414 15:47:51 InnoDB: The InnoDB memory heap is disabled
150414 15:47:51 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150414 15:47:51 InnoDB: Compressed tables use zlib 1.2.7
150414 15:47:51 InnoDB: Using Linux native AIO
150414 15:47:51 InnoDB: Initializing buffer pool, size = 128.0M
150414 15:47:51 InnoDB: Completed initialization of buffer pool
150414 15:47:51 InnoDB: highest supported file format is Barracuda.
150414 15:47:51  InnoDB: Waiting for the background threads to start
150414 15:47:52 Percona XtraDB (http://www.percona.com) 5.5.40-MariaDB-36.1 started; log sequence number 14440827849
150414 15:47:52 [Note] Plugin 'FEEDBACK' is disabled.
150414 15:47:52 [Note] Server socket created on IP: '0.0.0.0'.
150414 15:47:52 [Note] Event Scheduler: Loaded 0 events
150414 15:47:52 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.40-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server


И вот что в my.cnf

cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
net_read_timeout= 180
# Я дописал net_read_timeout= 180
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
  • Вопрос задан
  • 1275 просмотров
Решения вопроса 1
sim3x
@sim3x
В интернетах предполагают, что или кто-то рестатартит сервер, или кто-то получил привилегии и рестартит сервис, или что max_connections= может помочь

https://www.google.com/search?q=%2Fusr%2Flibexec%2...
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
lightarhont
@lightarhont
python/php developer
В принципе можно повесить перехват этой ошибки, что-бы он перезапускал сам сервер. Но как это сделать я пока не знаю...
Ещё есть supervisor.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы