IP address could not be resolved: Name or service not known
[root@test ~]# /usr/local/mysql/bin/mysqld
2018-08-05T07:00:33.647509Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-08-05T07:00:33.647654Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.12) starting as process 12515
2018-08-05T07:00:34.591235Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2018-08-05T07:00:34.591283Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2018-08-05T07:00:34.664056Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-08-05T07:00:34.695818Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.12' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server - GPL.
2018-08-05T07:06:56.802280Z 8 [Warning] [MY-010055] [Server] IP address '211.161.60.12' could not be resolved: Name or service not known
mysql could not be resolved: Name or service not known_Mysql_脚本之家 https://www.jb51.net/article/70893.htm
问题: mysql DNS反解:skip-name-resolve
错误日志有类似警告:
1.120119 16:26:04 [Warning] IP address '192.168.1.10' could not be resolved: Name or service not known
2.120119 16:26:04 [Warning] IP address '192.168.1.14' could not be resolved: Name or service not known
3.120119 16:26:04 [Warning] IP address '192.168.1.17' could not be resolved: Name or service not known
通过show processlist发现大量类似如下的连接:
1.|592|unauthenticated user|192.168.1.10:35320|NULL|Connect| |login|NULL|
2.|593|unauthenticated user|192.168.1.14:35321|NULL|Connect| |login|NULL|
3.|594|unauthenticated user|192.168.1.17:35322|NULL|Connect| |login|NULL|
skip-name-resolve 参数的作用:不再进行反解析(ip不反解成域名),这样可以加快数据库的反应时间。
修改配置文件添加并需要重启:
skip-name-resolve
其实就是在[mysqld]下面一行加入skip-name-resolve重启mysql服务就可以了。
下面是更加详细的解释:
现象:
程序连接mysql时,mysql的error.log里面提示:
[Warning] IP address '10.0.0.220' could not be resolved: Name or service not known
原因:
Mysql数据库服务器没有配置 /etc/hosts,也没有DNS服务,导致mysqld线程解析IP对应的主机名时,解析失败。
参考资料:
Mysql域名解析:
当一个新的客户端尝试跟mysqld创建连接时,mysqld产生一个新线程来处理这个请求。新线程会先检查请求建立连接的主机名是否在Mysql的主机名缓冲中,如果不在,线程会尝试去解析请求连接的主机名。
解析的逻辑如下:
a. Mysql线程通过gethostbyaddr()把获取的IP地址解析成主机名,然后通过gethostbyname()把获取的主机名解析成IP地址,保障主机名和IP地址对应关系的准确;
b. 如果操作系统支持使用安全进程的gethostbyaddr_r()和gethostbyname_r() 调用,Mysqld线程可以用它俩来优化主机名解析;
c. 如果操作系统不支持安全线程调用,Mysqld进程先做一个互斥锁,然后调用gethostbyaddr()和gethostbyname()解析主机名。此时,在第一个进程释放掉主机名缓冲池的主机名之前,其它进程无法再次解析这个主机名; <-------MySQL手册里面在此处说的host name ,意思应该是指同一个IP地址和对应的第一个主机名关系。
在启动mysqld进程是,可以使用 --skip-name-resolve 参数禁用DNS的主机名解析功能,禁用该功能后,在MySQL授权表里面,你只能使用IP地址。
如果你所处环境的DNS非常慢 或者 有很多主机, 你可以通过禁用DNS解析功能--skip-name-resolve 或者 提高 HOST_CACHE_SIZE大小 来提升数据库的响应效率。
禁用主机名缓冲的发方法: 使用--skip-host-cache 参数; 刷新主机名缓冲区: 执行 flush hosts 或者执行mysqladmin flush-hosts;
禁用TCP/IP连接: 使用--skip-networking参数。
实验:
# grep 192.168.1.1 /etc/hosts
192.168.1.1 hostname_online
sql> grant usage on *.* to root@'h_tt_%' identified by 'root';
sql> flush hosts;
# mysql -h 192.168.1.1 -uroot -proot
ERROR 1045 (28000): Access denied for user 'root'@'hostname_online' (using password: YES) ### IP解析为hostname_online,不是h_tt_%,访问被拒。
# grep 192.168.1.1 /etc/hosts
192.168.1.1 hostname_online
192.168.1.1 h_tt_1
# mysql -h 192.168.1.1 -uroot -proot
ERROR 1045 (28000): Access denied for user 'root'@'hostname_online' (using password: YES)#### mysqld没有刷新主机池缓冲池中的IP和主机名信息,此时IP对应hostname_online
sql> flush hosts;
# mysql -h 192.168.1.1 -uroot -proot
ERROR 1045 (28000): Access denied for user 'root'@'hostname_online' (using password: YES) #### mysqld解析了/etc/hosts里面同一个IP对应的第一个主机名关系时,就不再解析后面这个IP对应的主机名关系
# grep 192.168.1.1 /etc/hosts
192.168.1.1 h_tt_1
192.168.1.1 hostname_online
sql> flush hosts;
# mysql -h 192.168.1.1 -uroot -proot
sql> exit
【实验:】验证解析相同IP对应的第一个主机名关系后,就不再解析相同IP:
Sql>grant usage on *.* to root@'h_tt_%' identified by ‘root';
Sql>flush hosts;
# grep h_tt /etc/hosts # grep h_tt /etc/hosts
192.168.1.1hostname_online 192.168.1.1h_tt_1
192.168.1.1h_tt_1 192,168.1.2h_tt_1
访问mysql被拒绝; 从两个IP都可以访问mysql.
【结论】
此实验验证了,上述mysql手册中对"How MySQL Uses DNS"的解释。
即mysqld线程解析/etc/hosts是,是以IP作为唯一标识的,及时一个IP对应了多个主机名,但是mysqld线程只解析第一条对应关系,不论后面有几条这个IP对应的不同主机名的记录,Mysqld进程都不会去解析,都是无效的。
【适用环境:】
没有DNS服务器,主机非常非常多,或者 不想维护/etc/hosts里面手动配置的IP和主机名对应列表时,可以在mysql授权时执行主机名为"%" 或者禁用IP和主机名解析功能(--skip-name-resolve)。
IP address could not be resolved: Name or service not known的更多相关文章
- IP address could not be resolved: Temporary failure in name resolution
今早发现mysql日志中有非常多例如以下的警告: 140724 18:41:25 [Warning] IP address '172.16.18.217' could not be resolved: ...
- MySQL [Warning]: IP address 'xxxx' could not be resolved: Name or service not known
MySQL的error log 出现大量的 DNS反解析错误. DNS解析是指,将 域名解析成ip地址: DNS反解析是指,将IP地址反解析成域名: Version: MySQL Community ...
- IP address '121.41.35.30' could not be resolved: Name or service not known解决方法
IP address '121.41.35.30' could not be resolved: Name or service not known解决方法 添加如下 然后重启 即可解决<pre ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法
远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...
- oracle 11g RAC安装节点二执行结果错误CRS-5005: IP Address: 192.168.1.24 is already in use in the network
[root@testdb11b ~]# /u01/app/oraInventory/orainstRoot.sh Changing permissions of /u01/app/oraInvento ...
- Assign an Elastic IP Address to Your Instance
By default, an instance in a nondefault VPC is not assigned a public IP address, and is private.You ...
- Ubuntu setup Static IP Address
Change Ubuntu Server from DHCP to a Static IP Address If the Ubuntu Server installer has set your se ...
- How to configure a static IP address on CentOS 7(CentOS7静态IP地址设置)
Question: On CentOS 7, I want to switch from DHCP to static IP address configuration with one of my ...
- Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP
<Windows Azure Platform 系列文章目录> 本文介绍的是由世纪互联运维的Windows Azure China. 相比于Global Azure (http://www ...
随机推荐
- Linux 虚拟地址与物理地址的映射关系分析【转】
转自:http://blog.csdn.net/ordeder/article/details/41630945 版权声明:本文为博主(http://blog.csdn.net/ordeder)原创文 ...
- Linux内存管理【转】
转自:http://www.cnblogs.com/wuchanming/p/4360264.html 转载:http://www.kerneltravel.net/journal/v/mem.htm ...
- 标准C程序设计七---102
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- Linux内核解析之标准I/O库
当Linux创建一个进程时,会自动创建3个文件描述符0,1,2,分别对应标准输入,标准输出,错误输出.C库中与文件描述符对应的是文件指针.查看C库头文件stdio.h中的源码 typedef stru ...
- docker mysql 导入导出数据
导出数据 1.导出mysql单张表结构和数据: docker exec -it my-mysql mysqldump dbname -uroot -p123456 --tables tname > ...
- LeetCode OJ——Longest Valid Parentheses
http://oj.leetcode.com/problems/longest-valid-parentheses/ 最大括号匹配长度,括号是可以嵌套的 #include <string> ...
- 如何让一个现有的程序集运行在Silverlight环境中
故事是这样的:我们有一个组件,是一个标准的Class Library,里面有一些代码是实现了某些计算或者业务逻辑.例如下面这样 然后,我们做了一个Silverlight的应用程序,和一个用于运行该程序 ...
- guava之cache
转自:http://ifeve.com/google-guava-cachesexplained/ 范例 01 LoadingCache<Key, Graph> graphs = Cach ...
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟
原题链接:http://codeforces.com/contest/572/problem/B 题意 很迷,自行看题. 题解 看懂题就会做了 代码 #include<iostream> ...
- luogu P1140 相似基因
题目背景 大家都知道,基因可以看作一个碱基对序列.它包含了4种核苷酸,简记作A,C,G,T.生物学家正致力于寻找人类基因的功能,以利用于诊断疾病和发明药物. 在一个人类基因工作组的任务中,生物学家研究 ...