how to use mysql-connector-c++ 8.0: Cannot connect to remote Alibaba cloud database hosted

139 Views Asked by At

Can anyone tell me the answer, I have been unable to eat for a few days, thank you for being my benefactor

I'm using the mysql-connector-c++ 8.0 to mysql 8.0.x I want to connect to a remote cloud database. After trying countless times, I have encountered great difficulties. Is there something wrong with my code? I am a newbie to msyql The strange thing is that mysql - h xxx - root - p can be executed on the linux command line, but it fails in c++ alone, and the error is always one:

CDK Error: Connection attempt to the server was aborted. Timeout of 10000 milliseconds was exceeded 
#include <iostream>
#include <string>
#include <list>
#include <cstdlib>

#include <mysqlx/xdevapi.h>

using namespace mysqlx;

int main() {
    try {
        Session sess(SessionOption::USER, "root",
                     SessionOption::PWD, "123456",
                     SessionOption::HOST, "172.29.207.112",
                   //SessionOption::HOST, "rm-bp1qp1x588kzb49rf.mysql.rds.aliyuncs.com",
                     SessionOption::PORT, 33060,
                     SessionOption::DB, "demo");

        auto result = sess.sql("select * from person").execute();

        for (auto row : result.fetchAll()) {
            std::cout << row[0] << " " << row[1] << "\n";
        }
        
    } catch (const std::exception& e) {
        std::cerr << e.what() << '\n';
    }
}

1

There are 1 best solutions below

0
Driver On

I finally know the answer. The reason is that the cloud database provider does not support 33060 of X Protocol. Currently, Alibaba Cloud does not support it. I learned this from the intelligent problem robot, but it is not mentioned in the document. Alibaba Cloud should update documentation! !