本文已参与「新人创作礼」活动,一起开启掘金创作之路。
MYSQL 连接缓慢
问题
2018-05-17 16:29:37 5663 [Warning] InnoDB: Missing hive/VERSION.ibd file for table hive/VERSION.\
2018-05-17 16:35:29 5663 [Warning] InnoDB: Tablespace 'hive/BUCKETING_COLS' exists in the cache with id 2624 != 2625
2018-05-17 16:35:29 5663 [Warning] InnoDB: Freeing existing tablespace 'hive/BUCKETING_COLS' entry from the cache with id 2625
2018-05-18 10:05:07 5663 [Warning] IP address '10.0.2.4' could not be resolved: Name or service not known
2018-05-21 09:59:47 5663 [Warning] IP address '10.0.2.12' could not be resolved: Name or service not known
2018-05-22 09:03:41 5663 [Warning] IP address '10.0.2.5' could not be resolved: Name or service not known
2018-05-22 10:21:54 5663 [Warning] IP address '10.0.2.7' could not be resolved: Name or service not known
2018-05-23 08:39:51 5663 [Warning] IP address '10.0.2.2' could not be resolved: Name or service not known
2018-05-23 09:25:01 5663 [Note] /usr/sbin/mysqld: Normal shutdown
2018-05-23 09:25:01 5663 [Note] Giving 86 client threads a chance to die gracefully
2018-05-23 09:25:01 5663 [Note] Event Scheduler: Purging the queue. 0 events
2018-05-23 09:25:01 5663 [Note] Shutting down slave threads
2018-05-23 09:25:03 5663 [Note] Forcefully disconnecting 83 remaining clients
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 724 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 1249 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 941 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 1035 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 1265 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 1268 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 1266 user: 'root'
2018-05-23 09:25:03 5663 [Warning] /usr/sbin/mysqld: Forcing close of thread 1038 user: 'root'
原因
出现该错误的原因:
MySQL 数据库服务器没有配置 /etc/hosts,也没有DNS服务,导致mysqld线程解析IP对应的主机名时,解析失败。
解决
解决方法:
使用--skip-name-resolve 参数禁用DNS的主机名解析功能,禁用该功能后,在MySQL授权表里面,你只能使用IP地址。
所以我们修改MySQL的my.cnf中的参数:
[mysqld]skip_host_cacheskip-name-resolve=1
could not be resolved: Temporary failure in name resolution 的警告,可以使用 skip_host_cache 来搞定;
而 could not be resolved: Name or service not known 的警告,可以通过 skip_name_resolve=1 来搞定。禁止了域名解析,显然就不会出该警告了。
注意:skip_host_cache=1 会报错。直接 skip_host_cache 或者 skip-host-cache 就行了。
修改之后,需要重启。
注意:mysql中的权限表,就不能使用域名了,必须使用IP地址来设置。
参数解释
--skip-name-resolveDo not resolve host names when checking client connections. Use only IP addresses. If you use this option, all Host column values\ in the grant tables must be IP addresses or localhost. See Section 8.12.6.2, “DNS Lookup Optimization and the Host Cache”.Depending on the network configuration of your system and the Host values for your accounts, clients may need to connect using an\ explicit --host option, such as --host=localhost, --host=127.0.0.1, or --host=::1.An attempt to connect to the host 127.0.0.1 normally resolves to the localhost account. However, this fails if the server is run\ with the --skip-name-resolve option, so make sure that an account exists that can accept a connection.\ \ For example, to be able to connect as root using --host=127.0.0.1 or --host=::1, create these accounts:CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root-password';CREATE USER 'root'@'::1' IDENTIFIED BY 'root-password';
--skip-host-cacheDisable use of the internal host cache for faster name-to-IP resolution. In this case, the server performs a DNS lookup every time\ a client connects. See Section 8.12.6.2, “DNS Lookup Optimization and the Host Cache”.Use of --skip-host-cache is similar to setting the host_cache_size system variable to 0, but host_cache_size is more flexible\ because it can also be used to resize, enable, or disable the host cache at runtime, not just at server startup.If you start the server with --skip-host-cache, that does not prevent changes to the value of host_cache_size, but such changes\ have no effect and the cache is not re-enabled even if host_cache_size is set larger than 0.
其实,按照上面的介绍,如果我们启用了 skip-name-resolve=1, 那么因为禁止了 ip 和 hostname 之间的解析,那么就没有必要启用 skip-host-cache 了。启用的话,可能会减少一点点内存的占用吧?
参考