zoukankan      html  css  js  c++  java
  • 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 variable
      mysql>
      失败了,看来是只有修改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.

      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 服务即可。

  • 相关阅读:
    10分钟学会Python
    Python接口自动化(二)接口开发
    Python接口自动化(一)接口基础
    去掉webstorm内容区域右侧的一条竖线
    webstorm识别element-ui的标签
    vue中点击复制粘贴功能 clipboard 移动端
    vue pc element-ui class
    禁止浏览器记住密码
    js 将网络图片格式转为base64 canvas 跨域
    移动端网页在本地服务器调试
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3253907.html
Copyright © 2011-2022 走看看