Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
124 views
in Technique[技术] by (71.8m points)

How do you use the MySQL Connector/C++ and XDevAPI while using XAMPP to run MySQL?

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?

question from:https://stackoverflow.com/questions/66054267/how-do-you-use-the-mysql-connector-c-and-xdevapi-while-using-xampp-to-run-mysq

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I can tell, XAMPP is now based on MariaDB and not MySQL. The MySQL X DevAPI Connectors use the X Protocol (port 33060, by default, on a MySQL server instance) which isn't available on MariaDB.

MariaDB supports the classic MySQL protocol (port 3306), but you can't use X DevAPI clients over that protocol.

So either you find a way to use MySQL 8.x server or you will need a classic protocol connector.

Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...