【问题标题】:Connecting to remote mysql server using MacOS Terminal command line使用 MacOS 终端命令行连接到远程 mysql 服务器
【发布时间】:2017-01-26 16:38:41
【问题描述】:

我浏览了整个互联网,但找不到正确的答案。我正在学习 php/mysql 并在 gearhost.com 的远程 mysql 服务器上有数据库,我想连接到该服务器以进行培训。我想使用命令行而不是 phpMyAdmin 来处理数据库。

我的问题是:如何使用终端连接到数据库?有没有可以使用的命令,还是我需要先在 MacOS 中安装一些东西?

【问题讨论】:

    标签: mysql macos terminal


    【解决方案1】:

    您需要安装 MySQL 客户端才能在终端中访问远程 MySQL 服务器。可以通过Homebrew轻松安装。

    1. 要安装 Homebrew,请在终端中运行此命令(有关 Homebrew 和安装的更多信息,请访问其网站):

      $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
      
    2. 要安装 MySQL 客户端,请在终端中运行以下命令:

      $ brew install mysql
      
    3. Login 在浏览器中的 GearHost 帐户中。

    4. 在您的帐户中打开 Databases 部分。
    5. 找到您的数据库的主机(例如:mysqlx.gear.host)、用户名和密码。
    6. 在您的终端中运行此命令以访问您的数据库。将USER 替换为您的用户名,将mysqlx.gear.host 替换为您的主机。按下 enter 后,命令会询问您的密码。

      $ mysql -u USER -h mysqlx.gear.host -p
      

      输出应该是这样的:

      $ mysql -u USER -h mysqlx.gear.host -p
      Enter password:
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 3304987
      Server version: 5.7.17-log MySQL Community Server (GPL)
      
      Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
      
      Oracle is a registered trademark of Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their respective
      owners.
      
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      mysql>
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多