[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不反解成域名),这样可以加快数据库的反应时间。

修改配置文件添加并需要重启:

复制代码代码如下:
[mysqld] 
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的更多相关文章

  1. 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: ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Ubuntu setup Static IP Address

    Change Ubuntu Server from DHCP to a Static IP Address If the Ubuntu Server installer has set your se ...

  8. 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 ...

  9. Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

    <Windows Azure Platform 系列文章目录> 本文介绍的是由世纪互联运维的Windows Azure China. 相比于Global Azure (http://www ...

随机推荐

  1. 转 Centos下安装apahce的configure: error: APR not found. Please read the documentation解决办法

    转自: http://www.cnblogs.com/Anker/p/3355573.html 今天从Apache官网上http://httpd.apache.org/下载httpd web服务器,由 ...

  2. 反汇编->C++虚函数深度分析

    先来查看一简单例子 #include<iostream> using namespace std; class Base{ public: virtual void f() { cout ...

  3. hdu 5701(区间查询思路题)

    中位数计数 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  4. 解决npm 的 shasum check failed for错误

    使用npm安装一些包失败,类似如下报错情况:   C:\Program Files\nodejs>npm update npm npm ERR! Windows_NT 10.0.14393 np ...

  5. 使用redis-stat来监控redis实例

    https://blog.csdn.net/xiao_jun_0820/article/details/78189576 https://blog.csdn.net/u010022051/articl ...

  6. 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...

  7. Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟

    原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include< ...

  8. Noip2017赛前的一些记录

    前言 已经退役整整五个月了....选考以后终于又摸上了键盘.... 但是码力已经大不如前了........ 距离比赛也就只有一星期了....那就胡乱的做一些题目吧QAQ 这里是一些根据算法分类的咋杂题 ...

  9. 《从0到1》读书笔记第一章&quot;未来的挑战&quot;第2记:做老子还是做孙子

    从1到N VS 从0到1 - 别让自己的小鸡鸡抓在别人的手上 近几年国内互联网创业上非常流行一种C2C(也就是Copy to China - 复制到中国)的创业模式,打的就是一个时间差和地域差.将在国 ...

  10. mysql查询处理顺序

    http://zhangzhaoaaa.iteye.com/blog/1689412参考:<MYSQL技术内幕SQL编程> select distinct <selectlist&g ...