天天看点

mysqldump: Error 2013

最近在mysqldump时,遭遇mysqldump: Error 2013错误。以为是常见的参数设置有问题,调整之后,也没有任何成效。原来发生了OOM,以下是其具体描述。

一、故障现象

环境
# more /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

# mysql -V           ##PXC 5.7
mysql  Ver 14.14 Distrib 5.7.20-18, for Linux (x86_64) using  6.2

# mysqldump -hlocalhost -uroot -p --port=33006 --default-character-set=utf8 -F -R -E --triggers -e  \
>  --single-transaction --all-databases >/tmp/alldb.sql
Enter password: 
mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `tel_send_log` at row: 390486
表并不是很大,也就200w左右的数据行。           

二、故障分析

起初以为是相关变量设置有问题,因此调整相关参数
mysql > set global connect_timeout=1800;
mysql > set global net_read_timeout=1800;
mysql > set global net_write_timeout=1800;
mysql > set global max_allowed_packet=1024*1024*1024;
mysql > set global net_buffer_length=1024*1024;

之后再次导出,问题依旧,而且报错之后,mysqld就直接挂了
查看mysqld的error log也未得到相关报错的具体信息,还以为是版本太新遭遇Bug呢
后来加上一个选项--skip-extended-insert(这个是不启用mysql 生成insert包含多values)也不行
换到另一个节点后,导出却是正常的。
于是打开报错系统日志message一看,竟然out of memory

# tail -fn 50 /var/log/message
Apr 26 15:13:10 zcd kernel: Out of memory: Kill process 10274 (firewalld) score 5 or sacrifice child
Apr 26 15:13:10 zcd kernel: Killed process 10274 (firewalld) total-vm:333984kB, anon-rss:21980kB, file-rss:44kB, shmem-rss:0kB
Apr 26 15:13:10 zcd systemd: firewalld.service: main process exited, code=killed, status=9/KILL
Apr 26 15:13:10 zcd mysqld_safe: /usr/bin/mysqld_safe: line 220:  9658 Killed                
   nohup /usr/sbin/mysqld --basedir=/usr --datadir=/u02/pxcdata --plugin-dir=/usr/lib64/mysql/plugin --user=mysql 
  --wsrep-provider=/usr/lib64/galera3/libgalera_smm.so --log-error=/var/log/mysqld.log 
  --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock --port=33006
  --wsrep_start_position=e12b32d1-06f1-11e8-b907-d7b0846b449d:68722 < /dev/null > /dev/null 2>&1
Apr 26 15:13:10 zcd mysqld_safe: 2018-04-26T07:13:10.742581Z mysqld_safe Number of processes running now: 0
Apr 26 15:13:10 zcd mysqld_safe: 2018-04-26T07:13:10.831232Z mysqld_safe WSREP: not restarting wsrep node automatically
Apr 26 15:13:10 zcd mysqld_safe: 2018-04-26T07:13:10.835441Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

于是重启mysql,然后再次导出,观察内存占用情况,如下,可以看到free列值不断减少
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r  b  swpd  free  buff  cache  si  so    bi    bo  in  cs us sy id wa st
1  1      0 625288  31836 1347284    0    0 19840  372 3181 3394  9  3 42 46  0
0  1      0 586820  31844 1365304    0    0 19840    60 2385 3264  7  3 46 44  0
0  1      0 515076  31956 1400024    0    0 19312  564 2681 3327  7  4 43 46  0
0  1      0 478708  31964 1417948    0    0 20368    24 3057 3301  8  4 43 46  0
0  1      0 400960  31964 1452688    0    0 19840    0 2213 3278  7  3 44 47  0
0  1      0 364868  31964 1468268    0    0 19840 24648 3053 3500  7  4 40 50  0
0  2      0 324640  31976 1488112    0    0  4544 43656 1079 1688  2  2 14 83  0
0  1      0 286768  32116 1505272    0    0 19840  760 3412 3877  7  5 25 64  0
0  1      0 248916  32132 1520528    0    0 19840    36 4065 5746 13  4 43 41  0
0  1      0 127684  30816 1523336    0    0 24064               

继续阅读