Philpot
Philpot

Reputation: 246

Open MySQL from the terminal

I have installed MySQL on my macbook and would like to access MySQL through the terminal by simply typing mysql. How do I do this?

Upvotes: 0

Views: 5532

Answers (2)

jaaaaaaaaaavid
jaaaaaaaaaavid

Reputation: 1

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

. ~/.bash_profile

mysql -u root -p

Upvotes: 0

Philpot
Philpot

Reputation: 246

You need to add MySQL to the $PATH so when you type in mysql into the terminal, it will load.

To do this you need to open the terminal and type the following:

sudo nano /etc/profile

You'll then be asked for your computer password (not your MySQL password). GNU Nano will then open. Type the following:

export PATH=/usr/local/mysql/bin:$PATH

Press CTRL O, Enter then CTRL X.

Type into terminal:

source /etc/profile

You're now ready to start using MySQL from the terminal. Make sure the MySQL Server is running (easiest way is to open system preferences -> MySQL -> start MySQL Server).

In the terminal, to open MySQL, type the following (you'll be asked for the password for your connection):

mysql -u root -p

You can change root to whatever the MySQL connection username is. To make sure you're connected to the right connection, type: show

show databases;

This will show you the databases available on the MySQL connection you've opened.

Upvotes: 2

Related Questions