MySql客户端远程连接MySql服务器

  1. 设置MySql服务器以接听端口及以绑定IP地址

    • MySql服务器默认监听3306端口,确定防火墙以开放此端口。
    • 编辑/etc/my.cnf 添加绑定IP地址。bind-address=192.168.42.135
    • 重启MySql服务器,查看监听状态。
      [server@bogon ~]$ netstat -lnt
      Active Internet connections (only servers)
      Proto Recv-Q Send-Q Local Address Foreign Address State
      tcp 0 0 192.168.42.135:3306 0.0.0.0:* LISTEN
  2. 创建用户

    CREATE USER IF NOT EXISTS 'ubuntu'@'192.168.42.136' IDENTIFIED BY '[email protected]';
    192.168.42.136: 为客户端ip
    ubuntu: 用户名
    [email protected]: 登入密码
    此用户只允许在IP地址为192.168.42.136的客户机登入,如果要此用户在任意客户机登入,则将192.168.42.136改为%

  3. 安装MySql客户端(以ubuntu为例)

    • apt install mysql-client-X.X
    • 使用以下命令登入 mysql -h 192.168.42.135 -u ubuntu -p
      192.168.42.135: 为mysql服务器的IP地址

猜你喜欢

转载自www.cnblogs.com/Focus-Flying/p/9296517.html