Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is mySQL connecting at any/all ports

I'm running Linux Mint and trying to connect to mySQL this way

mysql --port=3306 -u root -p

Then it prompts me for my password. This is all fine. Why is it that when I type something like this it still works....

mysql --port=1234 -u root -p

Should that not fail since there is no mySQL server running on port 1234?

The reason I am asking this is because I want to create a SSH tunnel to connect to a database on another server. Let's say the SSH tunnel will forward all my traffic from localhost:3308 to myremoteserver:3306. Since my local mySQL server is accepting my connections on all ports, I cannot actually connect to port 3308 and hit the remote server. I am still hitting my local server....

Even if my SSH tunnel options might have been wrong, I was wondering if anyone knew why I can connect to port 1234 and it still hit my local mySQL server running on 3306?

like image 904
Girish Dusane Avatar asked Dec 09 '10 07:12

Girish Dusane


People also ask

What port does MySQL use to connect to?

IIRC mysql connects you to a Unix socket if you are connecting to localhost. Since it does not connect you via TCP in this case, there is no port involved and the port number you give does not matter.

Why can't I Access MySQL on my server?

Under Linux or Unix, check your IP tables (or similar) configuration to ensure that the port has not been blocked. Under Windows, applications such as ZoneAlarm or Windows Firewall may need to be configured not to block the MySQL port. The grant tables must be properly set up so that the server can use them for access control.

How do I SSH into a local port in MySQL?

If you want to connect to an SSH tunnel which uses a local port, I suggest also specifying the host at the mysql client prompt. mysql --port=3308 -hlocalhost -u root -p. This would prevent your mysql client from using a Unix pipe to connect to your server. Also, take a look at the [client] section of /etc/my.cnf.

Why can't I connect from a different host in MySQL?

If the following error occurs when you try to connect from a host other than the one on which the MySQL server is running, it means that there is no row in the user table with a Host value that matches the client host:


1 Answers

To force a TCP connection use --protocol=TCP.

Example:

First the SSH tunnel

ssh -L 4000:localhost:3306 server.ch

and then connect to the remote mysql server with

mysql -h localhost --port=4000 --protocol=TCP -u root -p
like image 51
P0P3Y Avatar answered Sep 23 '22 02:09

P0P3Y