Search code examples
c++mysqloraclemysql-connector-c

mysql-connector-c++ 8.0 connection refused


I'm using the mysql-connector-c++ 8.0 after getting it working with great difficulty and now the uri I've entered is as their mentioning in the docs but the connection is refused.

What the doc says:

Client cli("user:password@host_name/db_name", ClientOption::POOL_MAX_SIZE, 7);

My Code:

_mysql_client = std::make_unique<mysqlx::Client>("mysqlx://root:asdasd@localhost/asdasd");

    try {
        mysqlx::Session s = _mysql_client->getSession();
        CoreLog->info("Successfully connected to mysql server on {}.", conn_uri);
    } catch (const mysqlx::Error &err) {
        CoreLog->info("Could not connect to mysql server on {} due to {}.", conn_uri, err.what());
    }

and i get this error

[20:34:36.993] Core: Could not connect to mysql server on root:asdasd@localhost/asdasd due to CDK Error: Connection refused (generic:61).

What's the issue here?


Solution

  • mysqlx::Client is for connection to the new Mysql X protocol. This listens on a different port (33060 by default instead of 3306) which is the cause of the "connection refused" message.

    You need to install and enable the Mysql protocol X plugin. See https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install.html for instructions.