Good day.

Half a day I can not understand what the problem is. I have mysql-server installed on my server (CentOS6). And the other sulfur is still the same.

An SSH tunnel is raised to a remote server, which on port 3307 "hooks" the remote mysql.

I launch terminal localhost 3306 - it gives an invitation (there are krakozyabry, but there is a connection). I launch the terminal on port 3307 without a tunnel - I get an error, with a tunnel - the same cracker. I guess the tunnel is working correctly.

Neither perl nor the mysql console application can connect to the remote server.

from the mysql --host=localhost --port=3307 --user=dbuser --password=dbpassword dbname console mysql --host=localhost --port=3307 --user=dbuser --password=dbpassword dbname - returns an error

 RROR 1045 (28000): Access denied for user 'dbuser'@'localhost' (using password: YES) 

There is no such mysql user on the local server.

I execute mysql --host=localhost --port=3307 - connects, but to the local server (there are other databases there)

I execute mysql --host=localhost --port=33071 - it connects, but to the local server (there are other databases there)

Similar effect on remote server. Completely ignore the --port parameter.

And from Perl - the same effect (actually it is necessary to work there).

Can anyone come across a similar situation?

  • And write how the port was forwarded? It could not happen that you were forwarded from 3306 to 3307? So, by the way, it is often done in order not to screen the local port. - cheops
  • one
    I just found a solution ... I couldn’t fall asleep with my head yesterday and could not sleep at night ... I had to replace localhost with 127.0.0.1. Stackoverflow.com/questions/232121/… - KarDen
  • It is necessary to replace localhost 127.0.0.1 See ru.stackoverflow.com/questions/232121/… - KarDen

1 answer 1

There are two ways to connect to the MySQL server: through a socket and through the network. When you write localhost as a host - the default connection is through a socket, when you write an IP address - via the network. Therefore, in the case of localhost, the port directive is ignored - a network port is not needed for a socket connection.

In addition to explicitly specifying the IP address 127.0.0.1 instead of localhost, there is another solution - to redirect all connections through the network. To do this, in the configuration file my.cnf, you should detect and delete all socket directives and reload the server. At the same time, you should make sure that the server is tied to the current IP address

 [mysqld] ... bind-address = 0.0.0.0