zoukankan      html  css  js  c++  java
  • 配置远程连接mysql数据库 Connect to remote mysql database

    设有本地机器(local machine), ip地址为localip
    远程机器(remote machine), ip地址remoteip
    要通过在local machine的终端连接remote machine的mysql数据库,而且对数据库进行操作。

    1.在local和remote均安装好mysql,安装方法參考还有一篇博客。 2.在本地ssh连接到远程host $ ssh remoteuser@remoteip 3.打开远程host的mysql。为local加入用户。 $ mysql -uroot -p mysql>GRANT ALL ON *.* TO mysqluser@'localip' IDENTIFIED BY 'my_password'; //上述的GRANT 语句意思是在localip上创建一个mysql用户mysqluser,而且赋予该用户对本mysql的全部数据库的全部权限。

    4.查看步骤3的结果 mysql>select Host, User, Password from mysql.user; 5.完毕上述四个步骤后。在本地连接远程的mysql通常会失败,此时的原因有多种。能够參考下面链接中的方法。 <a target=_blank href="http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html">http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html</a> 自己的情况是进行了链接中的Step # 7: Open port 3306. 在步骤4以后输入quit退出mysql,但此时终端的host仍然是远程host。

    运行, $ sudo /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT $ sudo service iptables save 6.输入一下命令退出远程host,測试是否能连接到远程的mysql $ exit $ nc -z -w1 remoteip 3306 假设显示:Connection to <remoteip> port 3306 [tcp/mysql] succeeded! 则成功。便能够用mysql命令连接远程mysql。 $ mysql -u mysqluser -h remoteip -p


  • 相关阅读:
    通过system调用Am命令执行动作
    windows中如何在命令行启动启动程序
    UICC 实现框架和数据读写
    软件设计方法(转载)
    好诗欣赏——邀请 The Invitation
    leaflet使用turfjs插件,基于格点数据绘制等值线效果
    深信服防火墙做端口映射
    关于本博客的一些声明
    sqlserver – SQL Server – 包含多个字段的IN子句
    JavaScript Array join() 方法
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7106000.html
Copyright © 2011-2022 走看看