MySQL有关1042 Can’t get hostname for your address的问题分析_MySQL

php中文网
发布: 2016-06-01 13:31:06
原创
1453人浏览过

bitsCN.com

mysql有关1042 can’t get hostname for your address的问题分析解决过程

 

[Comment 1]

 前同事企鹅上面说他安装的mysql 5.5,发现用mysql客户端远程连接的时候,报1042-Can’t get hostname for your address错误,但是权限已经grant了并且grant成功了。

 这个报错的意思是“您的地址无法获得主机名”,我就想到了skip-name-resolve参数。

官方文档: 

--skip-name-resolve

Use IP addresses rather than host names when creating grant table entries. This option can be useful if your DNS does not work.

 

--skip-name-resolve

Do not resolve host names when checking client connections. Use only IP numbers. If you use this option, all Host column values in the grant tables must be IP numbers or localhost. See Section 7.7.11, “How MySQL Uses DNS”.

 

mysql> show variables like '%skip_name_resolve%';+-------------------+-------+| Variable_name     | Value |+-------------------+-------+| skip_name_resolve | ON   |+-------------------+-------+1 row in set (0.00 sec)mysql> set global skip_name_resolve=0;ERROR 1238 (HY000): Variable 'skip_name_resolve' is a read only variablemysql> 
登录后复制

 

失败了,看来是只有修改my.cnf了

 

在[mysqld]节点下修改

skip-name-resolve#忽略主机名的方式访问lower_case_table_names=1#忽略数据库表名大小写
登录后复制

 

重启MySQLD process即可。

 

 

[Comment 2]

前同事企鹅留言:

mysql -h 192.168.1.101 -u root -p
登录后复制

 

访问不了,我本地的mysql.192.168.1.101是本地ip地址。

grant all privileges on *.* to 'hive'@'192.168.1.101' identified by 'hive' with grant option;就是报连接不上,权限问题,怎么搞定。

查看官方文档:

hostname

Variable Name hostname

Variable Scope Global

Dynamic Variable No

  Permitted Values

Type string

The server sets this variable to the server host name at startup.

 

[html] mysql> show variables like '%hostname%';  +---------------+-------------------------------------------+  | Variable_name | Value                                     |  +---------------+-------------------------------------------+  | hostname      | xxxxx.china.online.xx.com |  +---------------+-------------------------------------------+  1 row in set (0.00 sec)    mysql> set global hostname='xxxxx2.china.online.xx.com';  ERROR 1238 (HY000): Variable 'hostname' is a read only variable  mysql>   
登录后复制

 

失败了,只有修改my.cnf了,在mysqld选项下面

 

[mysqld]# 注释掉参数即可,mysql直接用本机ip不能访问# hostname
登录后复制

 

然后重启mysqld 服务即可。

 

bitsCN.com
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号