MySQL Error:10061

MySQL

Apparently, I cannot connect to SQL server using the mysql.exe

I logged in as the root user and typed the following

mysql -u root -p
mysql> CONNECT TO 127.0.0.1:3306;

I receive the folling error.

ERROR 2005 (HY000): Unknown MySQL server host '127.0.01:3306' (2)

Unknown MySQL server host '127.0.0.1:3306' (2)

However it connects justs fine using MySQL Workbench with the same parameters.

Host:127.0.0.1
Port:3306
User: root
pass:[empty]

I have the easyphp MySQL module installed. Could this be the reason?

EDIT: TYPO with 127.0.0.1 sorry

Best Answer

According to the documentation, the syntax of the connect command is:

connect [db_name host_name]], \r [db_name host_name]]

Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.

Therefore your command CONNECT TO 127.0.0.1:3306 is attempting to connect to a database called TO on a host called 127.0.0.1:3306. The error message you receive in return unsurprisingly complains that the host does not exist.

However, it is more usual to specify the hostname and database on invoking mysql (whereupon one can also specify the port if one wishes - see this page for a full list of command line options):

mysql -u username -p -h <hostname> -P <port> db_name

Also note that if the hostname and port are not specified, they default to localhost and 3309 - therefore in your case you can omit all of the above and just go with:

mysql -u username -p db_name

To do what you're currently doing (not specifying the database name on the command-line), you must call the USE command at the mysql> prompt to select a database after you've connected:

mysql -u username -p
mysql> USE db_name;