zoukankan      html  css  js  c++  java
  • [转载]ac mysql 无法远程连接

    Mac mysql 无法远程连接

    版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
    本文链接:https://blog.csdn.net/feixiang2039/article/details/81164136

    现象:在 Mac 系统上,mysql 不允许远程连接。

    首先按照常规的方法操作: 
    进入 mysql: $ mysql -u root -p

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
    mysql> FLUSH PRIVILEGES;
    • 1
    • 2

    再次尝试连接,还是不行。

    后来发现,即使在本地使用 IP 也无法连接。那估计就是 mysql 服务绑定的 IP 有问题,要找到 mysql 的配置文件看看。

    当时用 Homebrew 安装的 mysql,查看 brew info mysql ,没有找到 mysql 配置文件的位置,却有这样一句话:

    MySQL is configured to only allow connections from localhost by default
    • 1

    查看 msyql --help ,mysql 提示会按照下面的顺序查找配置文件。

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
    • 1
    • 2

    最终发现,使用 Homebrew 安装 mysql,默认配置在 /usr/local/etc/my.cnf,内容是:

    # Default Homebrew MySQL server config
    [mysqld]
    # Only allow connections from localhost
    bind-address = 127.0.0.1
    • 1
    • 2
    • 3
    • 4

    顾名思义,bind-addres的配置绑定了本地IP,所以远程无法连接。再看看 mysql 官方文档, bind-address 的配置是这样描述的:

    If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces.

    If the server was started with —bind-address=127.0.0.1, it will listen for TCP/IP connections only locally on the loopback interface and will not accept remote connections.

    于是修改配置为: bind-address = 0.0.0.0 
    重启 mysql:brew services restart mysql

    再次尝试远程连接,终于通了。

  • 相关阅读:
    .Net反编译软件
    Windows下Node.js安装及环境配置
    Servlet处理日期
    Servlet的文件上传
    Eclipse错误:Syntax error on tokens, delete these tokens问题解决
    Servlet中操作数据库
    Servlet的会话(Session)跟踪
    Servlet的Cookies处理
    Servlet的异常处理
    Servlet的过滤器(Filter)
  • 原文地址:https://www.cnblogs.com/sanmuqingliang/p/11350657.html
Copyright © 2011-2022 走看看