0

I am trying to access a MySQL database in my C++ code. I have a feeling I may have messed something up along the way, so I'll outline what steps I took and my setup:

  • I installed MySQL Connector/C++
  • I installed MySQL XDevAPI
  • I installed XAMPP and set it up to run a MySQL server
  • I created a database with some tables in phpMyAdmin
  • I linked the Connector/C++ and MySQL Server libraries and includes in my C++ project
  • Then I added the following code:
#include <mysqlx/xdevapi.h>
#include <iostream>
using namespace mysqlx;

int main() {
    try {
        Session sess(33060, "user", "password");
    }
    catch (const Error & err) {
        std::cout << err << std::endl;
        exit(1);
    }

    return 0;
}

I tried this with the port 33060 as I was told that was the default, and I tried it with the port 3306 as that is what it says the port is on XAMPP.

Using the first gives this error message: "CDK Error: No connection could be made because the target machine actively refused it. (winsock:10061)" Using the second gives this error message: "CDK Error: unexpected message"

One thing that I suspect may be a problem is that the MySQL Server and C++ Connector files are in my Program Files on my C drive, while XAMPP seems to have a different set of MySQL files in its installation folder on my D drive. Did I somehow end up with 2 separate installations of MySQL or is there something else going on that I fail to understand? If so how do I handle this?

4

1 回答 1

2

据我所知,XAMPP 现在基于 MariaDB 而不是 MySQL。MySQL X DevAPI 连接器使用 MariaDB 上不可用的 X 协议(默认情况下,在 MySQL 服务器实例上的端口 33060)。

MariaDB 支持经典的 MySQL 协议(端口 3306),但您不能通过该协议使用 X DevAPI 客户端。

所以要么你找到一种使用 MySQL 8.x 服务器的方法,要么你需要一个经典的协议连接器

免责声明:我是 MySQL X DevAPI Connector for Node.js 的主要开发人员

于 2021-02-05T09:45:32.703 回答