Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to MySQL using command line but can using MySQL Workbench

I am successfully using MySQLWorkbench to access and manage a database at 127.0.0.1:3307.

However if I try to access it using the command line:

mysql -u admin -h 127.0.0.1:3307 -p

I get the error message:

ERROR 2005 (HY000): Unknown MySQL server host '127.0.0.1:3307' (0)

Why does it work with MySQLWorkbench and not with the command line?

I am running on OSX

like image 935
Bill Noble Avatar asked Oct 07 '15 10:10

Bill Noble


People also ask

Why MySQL is not working in CMD?

To fix the error, you need to make sure that the mysql.exe file is available under your PATH setting. The mysql.exe file is located on the bin/ folder of your MySQL program, but the location of your MySQL program will depend on what program you use to install MySQL on your computer.

Why MySQL database is not connecting?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

How do I fix MySQL connection refused?

Check that the DB username, DB password, database host, and database port are correct. (if you are unsure, reach out to your database administrator or check in your web hosting account for the up to date credentials). If the config file references host = "localhost" , you can try to change it to 127.0.


1 Answers

Because MySQLWorkbench parses out the port number, and the CLI tool doesn't. There is a separate option --port for providing it. Try

mysql --user admin --host 127.0.0.1 --port 3307 --password
like image 112
ivancho Avatar answered Sep 26 '22 14:09

ivancho