MySQL是使用Docker容器搭建起来的,在今天的数据库连接中,发现比平时的连接速度变慢了很多,每次连接大概延迟了10秒左右。 慢的很。项目中用肯定死逼了。
问题处理思路:
1 .服务器资源 查看系统的CPU、网络等负载,无异常
2 .数据库连接池 我都没在项目中用,肯定不是这个问题
3 .网络问题 在ping服务器的时候并没有出现数据包延迟、丢包现象。不是网络问题
4 .MySQL DNS解析。
百度了N久找到了个靠谱的。和我遇到的问题一样哒

解决它
找到你容器中的mysql配置文件 my.cnf ,增加skip-name-resolve
root@6af0f6d0b6e1:/# cd /etc/mysql/
root@6af0f6d0b6e1:/etc/mysql#
root@6af0f6d0b6e1:/etc/mysql# cat my.cnf
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
skip-name-resolve
root@6af0f6d0b6e1:/etc/mysql#
然后重启docker restart xxx(容器id)
这时候再去连接,速度和平时一样了,舒服~