Mac install and open mysql using terminal

Doug Fir picture Doug Fir · Jan 9, 2013 · Viewed 249.9k times · Source

I downloaded the mysql dmg file and went through the wizard to run. Done. I have also started mysql server under system preferences.

The purpose of me doing this is to work through the exercises of my SQL text book. The terminal commands are new to me but I think once I can actually get started, working through the exercises should be OK.

From researching the web the various blogs tell me to navigate to to the mysql folder in the terminal: /usr/local/mysql

Fine. Then it gets a little less clear as nearly each article has a different set of instructions on how to proceed. I was fiddling with it yesterday and was prompted for a password - what is the default mysql password?

Could someone give me the steps to get up and running with mysql via the terminal?

Answer

Gary G picture Gary G · Jan 9, 2013

(Updated for 2017)

When you installed MySQL it generated a password for the root user. You can connect using

/usr/local/mysql/bin/mysql -u root -p

and type in the generated password.

Previously, the root user in MySQL used to not have a password and could only connect from localhost. So you would connect using

/usr/local/mysql/bin/mysql -u root