0

problem: mysql_real_connect() will not establish connection with a remote db using an actual ip

current state: mysql_real_connect() establishes connection with local database. I am using Visual Studio Community 2017 Version 15.9.3, MySQL Workbench 8.0 Version 8.0.13 and Connector.C++ 1.1

void test_local_connection()
{
  MYSQL* conn;
  conn = mysql_init(0);
  conn = mysql_real_connect(conn, "localhost", "root", "password1", "schema1", 
  3306, NULL, 0);
  if (conn)
    cout << "connection establised" << endl;
  else error("connection failed - check settings");
}

question: what specific arguments do I need to pass to mysql_real_connect() to establish connection with a remote db? Does connection have to be established with root and root password, or can the connection be established with my user and my corresponding password?

void test_server_connection()
{
  MYSQL* conn;
  conn = mysql_init(0);
  conn = mysql_real_connect(conn, "actual.ip.address", "user", "password2", "schema2", 3306, NULL, 0);
  if (conn)
    cout << "connection establised" << endl;
  else error("connection failed - check settings");

}

  • Your best bet is to find out *why* the connect fails: see [mysql_error](https://dev.mysql.com/doc/refman/8.0/en/mysql-error.html). – rustyx Dec 29 '18 at 13:29
  • have a feeling the mysql user won't allow remote IP's or a firewall is blocking the request.. – Raymond Nijland Dec 29 '18 at 13:45
  • Eventually fixed problem and answered my question through an earlier post: https://stackoverflow.com/questions/8348506/grant-remote-access-of-mysql-database-from-any-ip-address – user_4572122a Mar 03 '19 at 14:20

0 Answers0