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 ...
随机推荐
- ExcelHelper类
/// <summary> /// ExcelHelper类 /// </summary> using System; using System.IO; using Syste ...
- CodeForces 380.C Sereja and Brackets
题意 一串括号序列,只由(和)组成,然后是m个提问,提问l和r区间内,最大的匹配匹配括号数. 思路 第一,贪心的思想,用最正常的方式去尽量匹配,详细点说就是,先找到所有的(),然后删除这些(),再找所 ...
- IOS 使用DSYM文件定位Bug 的具体位置
在项目的开发中,我们通常需要排查和修改测试中和发布后线上的一些bug,现在有一些第三方的bug分享和查找工具SDK,如腾讯的Bugly和听云等,包括苹果的开发工具xcode也自带 bug查找工具.那么 ...
- React-Native解决ListView 在Android手机上无吸顶效果
stickySectionHeadersEnabled={true} stickyHeaderIndices={[0]}
- 最小生成树-prim算法模板
题目描述 如题,给出一个无向图,求出最小生成树,如果该图不连通,则输出orz 输入输出格式 输入格式: 第一行包含两个整数N.M,表示该图共有N个结点和M条无向边.(N<=5000,M<= ...
- 洛谷—— P1407 工资
https://www.luogu.org/problemnew/show/P1407 题目描述 有一家世界级大企业,他们经过调查,发现了一个奇特的现象,竟然在自己的公司里,有超过一半的雇员,他们的工 ...
- UVA - 10615 Rooks
建一下模,把行和列看成二分图的点,把车看成是二分图中的边,这样就变成了上一个博客的问题. 我们每次新加一条边,就把它加入一条 这条边两端点最小没有出现的颜色 交替出现的路径中去. #include& ...
- Hdoj 3506 Monkey Party
Discription Far away from our world, there is a banana forest. And many lovely monkeys live there. O ...
- Bitmap 图片格式并用 C++ 读写 Bitmap
转自 Bitmap 图片格式并用 C++ 读写 Bitmap 1.Bitmap 图片格式 每部分的具体内容就不展开了.要说的有两点: (1)调色板不是必须的,可有可无,有没有调色板可以通过位图文件头的 ...
- [c++菜鸟]《Accelerate C++》读书笔记
第0章 开始学习C++ 1.<<的行为取决于它的操作数类型,<<会把它的右操作数的字符写到左操作数所指示的流中,他是结果就是它的左操作数. 2.std::endl是一个控制器, ...