MySQL 8 – connecting to server with different port

Posted on

Question :

I have MySQL 8 on Debian 9 vps, and my problem that I can connect to server from php Adminer (web) with any port I’ve chosen:

localhost:3307, 33650, any port.

And php Adminer showing – MySQL ยป localhost:33899. And I can manage databases, but this instance is from 3306, which is default. Why such thing is happen? Am I miss something? This question was born due of other question here – MySQL 8 insert values into selected columns only

And no other instances of MySQL are running in that case. Even if I run them, I can connect only from command line, not from Adminer web nor from game script side.

Answer :

This is because if you specify “-h localhost” – it will connect you to MySQL socket, and –port will be ignored (no TCP/IP will be used, and hence the –port option has no meaning).

To connect to a different port, simply use an address which is not “localhost”, but 127.0.0.1:

Credits to: https://lxadm.com/MySQL:_connecting_to_different_ports_on_localhost

So, I have to take care of 127.0.0.1:my port. Probably requires binding, etc.

So, finally it’s working now, the lesson I’ve learned that localhost isn’t the same as 127.0.0.1. I just made edit to *.cnf:

bind-address=127.0.0.1

Leave a Reply

Your email address will not be published.