user3502321
user3502321

Reputation: 1

Connecting to remote mysql server using MacOS Terminal command line

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

Answers (1)

Hamid Rouhani
Hamid Rouhani

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.

  1. 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)"
    
  2. To install MySQL client run this command in your terminal:

    $ brew install mysql
    
  3. Login in your GearHost account in your browser.

  4. Open Databases section in your account.
  5. Find the host (something like: mysqlx.gear.host), username and password of your database.
  6. 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

Related Questions