简体   繁体   中英

Connect mySQL via SSH error 2002

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.

我需要指定“ 127.0.0.1”而不是“ localhost”作为地址,因为我绑定的是IP本身,而不是实际的localhost。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM