Reputation: 1
I have looked all over internet but cannot find right answer. I am learning php/mysql and have database on a remote mysql server at gearhost.com which I would like to connect to in order to train. I would like to use command line instead of phpMyAdmin to work on database.
My question is: how do I connect to database using Terminal? Is there a command that work with it or do I need to install something into MacOS first?
Upvotes: 0
Views: 21236
Reputation: 2459
You need to install MySQL client to access to remote MySQL server in your terminal. It is easy to install it via Homebrew.
To install Homebrew run this command in your terminal (for more information about Homebrew and the installation navigate to its website):
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install MySQL client run this command in your terminal:
$ brew install mysql
Login in your GearHost account in your browser.
mysqlx.gear.host
), username and password of your database.Run this command in your terminal to access to your database. Replace USER
with your username and mysqlx.gear.host
with your host. After pressing enter, the command asks for your password.
$ mysql -u USER -h mysqlx.gear.host -p
The output should be something like this:
$ 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>
Upvotes: 7