mysql报错IP address could not be resolved解决方法

2017-07-08数据库
1410

这个警告不会影响数据库的访问 但是当有大量的这种日志产生的时候,数据库之前的错误信息 就会很难去查询了。连接数越多,产生报警日志的频率越高。

一、错误描述

数据库的alert.log中,我们经常会出现下面的警告:

IP address '172.16.12.195' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.67' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.67' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.195' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.195' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.195' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.196' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.196' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.195' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.195' could not be resolved: Temporary failure in name resolution
IP address '172.16.12.68' could not be resolved: Temporary failure in name resolution

二、问题产生的原因

出现错误的原因是MYSQL Server在本地内存中维护了一个非本地的Client TCP cache,这个cache中包含了远程Client的登录信息,比如IP地址,hostname等信息。

如果Client连接到服务器后,Mysql首先会在本地TCP池中根据IP地址解析客户端的hostname或者反解析,如果解析不到,就会去DNS中进行解析,如果还是解析失败

就是在error log中写入这样的警告信息。

三、解决的办法:

1、修改配置文件

可以通过两个参数来disable这个功能,在MYSQL的配置文件中[mysqld]中加入下面的参数:

[mysqld]
--skip-host-cache
--skip-name-resolve

重新授权,将所有访问数据库服务器的授权方式都改成IP形式的。

grant all on *.* to ‘root’@’172.16.12.68’identified by ‘123456’;

2、添加授权。

将所有访问数据库服务器的授权方式都改成IP形式。
不同的用户用不同的用户名和密码。

grant all on *.* to ‘user_68’@’172.16.12.68’identified by ‘pwd_68’;
grant all on *.* to ‘user_67’@’172.16.12.67’identified by ‘pwd_67’;
....

然后去 mysql数据库下面的 user表  和db表 下面删除掉那些含有含有主机名字的权限记录。

四、总结

1、要么加上

--skip-host-cache
--skip-name-resolve

使得MySQL将不再通过DNS解析地址。

2、赋予权限

要么在赋予权限的时候 直接用ip地址,去掉那些用主机名字的权限。

The End

相关推荐

liunx mysql root账户提示:Your password has expired. To log in yo
liunx mysql root账户提示:Your password has expired. To log in you must change it using a client that supports expired passwords,要怎么操作呢? 1、修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动...
2024-12-24 数据库
149

MySQL时间类型和模式详情
MySQL是一种流行的关系型数据库系统,它提供了多种时间类型和模式,用于存储和处理时间数据。本文将详细介绍MySQL时间类型和模式的详细攻略。...
2023-12-07 数据库
15

VMware中安装CentOS7(设置静态IP地址)并通过docker容器安装mySql数据库(超详细教程)
首先在官网下载CentOS7镜像,并在VMware虚拟机中新建一台CentOS7虚拟机,将镜像挂载到虚拟机中并启动。...
2023-12-07 数据库
11

SpringBoot项目报错:”Error starting ApplicationContext̷
首先,当我们使用Spring Boot开发项目时,可能会遇到Error starting ApplicationContext错误,一般这种错误是由于配置文件、依赖包或者代码逻辑等原因引起的。下面我将提供一条包含两条详细示例说明的完整攻略,用来解决上述问题。...
2023-12-07 数据库
489

MySQL中出现lock wait timeout exceeded问题及解决
MySQL中出现lock wait timeout exceeded问题的原因是由于两个或多个事物同时请求相同的资源造成的,并且在某一时刻至少一个事务无法获取资源,超过了MySQL默认的等待时间,从而导致事务失败。这种问题的出现会极大地影响数据库的性能和并发能力。...
2023-12-07 数据库
73

Mybatis Plus查询时sql字段名大小写报错的解决
针对Mybatis Plus查询时sql字段名大小写报错的解决这个问题,我提供以下完整攻略:...
2023-12-07 数据库
197