我查遍了互联网但找不到正确的答案。我正在学习 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)"
Run Code Online (Sandbox Code Playgroud)要安装 MySQL 客户端,请在终端中运行以下命令:
$ brew install mysql
Run Code Online (Sandbox Code Playgroud)在浏览器中登录您的 GearHost 帐户。
mysqlx.gear.host找到数据库的主机(类似于:) 、用户名和密码。在终端中运行此命令以访问数据库。替换USER为您的用户名和mysqlx.gear.host您的主机。按 后enter,该命令会要求您输入密码。
$ mysql -u USER -h mysqlx.gear.host -p
Run Code Online (Sandbox Code Playgroud)
输出应该是这样的:
$ 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>
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
19200 次 |
| 最近记录: |