Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to different port using MySql Command Line Client

By default I am being connected to port 3309.I need to connect to port 3307.How do I do that?

like image 820
Zafar Nasim Avatar asked Feb 12 '19 06:02

Zafar Nasim


People also ask

How do I connect to a different MySQL port?

How To Connect to MySQL Server on a Different Port? If your MySQL server is listening on port number different than 3306, you need to specify "--port=portNumber" option to any client program that needs to connect to the server.

How do I start MySQL on a specific port?

To do this, create an option file for each server and tell the server the file name with a --defaults-file option when you run it. Suppose that you want to run one instance of mysqld on port 3307 with a data directory of C:\mydata1 , and another instance on port 3308 with a data directory of C:\mydata2 .

What port does MySQL client use?

Client - Server Connection Ports Port 3306 is the default port for the classic MySQL protocol ( port ), which is used by the mysql client, MySQL Connectors, and utilities such as mysqldump and mysqlpump.


3 Answers

Use -P parameter, like this:

mysql -h 127.0.0.1 -P 3307 -u user_name -p database_name

Important: if you connecting to localhost - use -h 127.0.0.1, NOT localhost, because MySQL will connect by file socket, not by TCP

like image 160
Evgeny A. Mamonov Avatar answered Oct 05 '22 00:10

Evgeny A. Mamonov


From command line, assuming you are on the same host, have you tried :

mysql --user root --password (mypassword) --host=localhost --port=33061 

In server name specify custom port when not using default one (you can imply it only when is the standard mysql port 3306)

$servername = "localhost:33061";

like image 38
Matteo Avatar answered Oct 04 '22 22:10

Matteo


you can use -P (uppercase) or --port=portnumber sample

mysql -u root -P 13306 -p databasename

or

mysql -u root --port=13306 -p databasename
like image 36
Rendy The Code Avatar answered Oct 04 '22 23:10

Rendy The Code