From some application, I can’t connect to a remote database server:
MYSQL conn;
if(!mysql_init(&conn))
std::wcout << "Error: can't create MySQL-descriptor" << endl;
if(!mysql_real_connect(&conn,"ip","user","password","dbname",0,0,0))
std::wcout << "Error: can't connect to MySQL server" << endl;
if(mysql_query(&conn, "SELECT VERSION()") != 0)
std::wcout << "Error: can't execute SQL-query" << endl;
I opened port 3306 on the remote server:
iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
iptables save
iptables restart
Error:
Failed to connect to database:Error: Can’t connect to MySQL server on
‘ip_..’ (10060)
What could be the reason?
You should display result of mysql_error after every failed test (following a successful
mysql_init), e.g.:otherwise your user won’t be able to understand what is happening to him.
You’ll probably find out what is happening. If not, look into the documentation.