zoukankan      html  css  js  c++  java
  • MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法

    今天在测试MySQL的连接时候,发现连接不通过,并报错ERROR 2003 (HY000): Can't connect to mysql server on '192.168.10.210' (111) 
    测试代码:

    require 'mysql2'
    client = Mysql2::Client.new(:host=>"192.168.10.210",:username=>'root',:password=>"root")
    puts results = client.query("show databases;")

    谷歌了一下之后,原来是在mysql的my.cnf中有下面一段代码:

    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address           = 127.0.0.1  #这里默认监听本地localhost

    如果要让mysql监听到其他的地址,可以将bind-address = 127.0.0.1注释掉。 
    或者将bind-address = 0.0.0.0监听所有的地址

    屏蔽掉之后再次运行代码又出现:Host '192.168.10.83' is not allowed to connect to this MySQL server 
    这里写图片描述 
    解决方法: 
    如果想让192.168.10.83能够连接到本地的这个数据库,要让数据库给其分配权限,登录mysql,执行:(username 和 password是登录mysql的用户名和密码)

    GRANT ALL PRIVILEGES ON *.* TO 'username'@'192.168.10.83' IDENTIFIED BY 'password' WITH GRANT OPTION;

    如果要想所有的外部ip地址都能够访问使用mysql,可以执行下面:

    GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

    之后执行刷新数据库:

    flush privileges;

    如果要查看用户的权限,可以执行:

    > show grants for 'root'@192.168.10.83

    这里写图片描述

  • 相关阅读:
    预警:亚马逊出售的监控摄像机存在预装恶意软件
    opendaylight+openvswitch环境部署
    keepalived+nginx实现高可用
    Huawei ipv6 bgp配置
    F5配置http跳转https
    F5配置ssl卸载
    IBGP路由重分布进IGP路由
    H3C NQA 配置
    Cisco N7K第三方光模块的使用
    Cisco C3850交换机重启后配置无法保存的故障处理
  • 原文地址:https://www.cnblogs.com/zihanxing/p/7049244.html
Copyright © 2011-2022 走看看