MySQL: connecting to different ports on localhost

If you want to use mysql command to connect to MySQL server running on localhost, but on nonstandard port (not 3306), you may notice that whatever port you specify, it will connect you to the default MySQL server running on port 3306:

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: