【发布时间】:2017-01-26 16:38:41
【问题描述】:
我浏览了整个互联网,但找不到正确的答案。我正在学习 php/mysql 并在 gearhost.com 的远程 mysql 服务器上有数据库,我想连接到该服务器以进行培训。我想使用命令行而不是 phpMyAdmin 来处理数据库。
我的问题是:如何使用终端连接到数据库?有没有可以使用的命令,还是我需要先在 MacOS 中安装一些东西?
【问题讨论】:
我浏览了整个互联网,但找不到正确的答案。我正在学习 php/mysql 并在 gearhost.com 的远程 mysql 服务器上有数据库,我想连接到该服务器以进行培训。我想使用命令行而不是 phpMyAdmin 来处理数据库。
我的问题是:如何使用终端连接到数据库?有没有可以使用的命令,还是我需要先在 MacOS 中安装一些东西?
【问题讨论】:
您需要安装 MySQL 客户端才能在终端中访问远程 MySQL 服务器。可以通过Homebrew轻松安装。
要安装 Homebrew,请在终端中运行此命令(有关 Homebrew 和安装的更多信息,请访问其网站):
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
要安装 MySQL 客户端,请在终端中运行以下命令:
$ brew install mysql
Login 在浏览器中的 GearHost 帐户中。
mysqlx.gear.host)、用户名和密码。在您的终端中运行此命令以访问您的数据库。将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>
【讨论】: