0
votes

I'm trying to connect to my mySQL server with the C interface via a SSH tunnel.

What I currently do is open the SSH tunnel :

ssh user@IP -L 10293:127.0.0.1:3306

And then in code :

    MYSQL *conn = mysql_init(NULL);
    mysql_real_connect(conn, "localhost", "username", "password", "production", 10293, NULL, 0);

    unsigned int error = mysql_errno(conn);

I get the error 2002 just after having connecting. Error 2002 is "Can't connect to local MySQL server through socket". However, why is it trying to connect via socket when I didn't specify any socket in the connection?

What else could possibly go wrong?

Username, password and table name have been checked multiple times of course.

1
It's telling you basically it cannot connect. Sockets are used everywhere: en.wikipedia.org/wiki/Internet_socket My guess is that you do not have enough privileges to connect to the MySQL host. - AmazingDreams
Ha thanks, got it. I needed to specify "127.0.0.1" instead of "localhost" since I was binding to that IP and the actual localhost. - gcamp

1 Answers

1
votes

I needed to specify "127.0.0.1" instead of "localhost" as the address since I was binding the IP itself, and not the actually localhost.