首页 > 解决方案 > 如何使用 xdevapi 通过 C++ 代码登录 MySQL?

问题描述

我正在尝试使用构建连接器 c++ 通过 C++ 代码登录 MySQL,这是我删除密码的代码:

std::string url = "mysqlx://localhost:3306/license_db?user=licuser&password=**********";

会话我的会话(网址);

mySession.sql("使用 license_db").execute();

auto result = mySession.sql("SELECT * FROM product").execute();

行 row1 = result.fetchOne();

该代码导致“Session mySession(url);”出现异常 行和异常说“分配错误”。

有人可以帮忙吗?

标签: c++mysql

解决方案


X DevAPI的 URI 通常是mysqlx://user:password@host:3306/schema,适用于 JS、PHP 和 Python。

在https://dev.mysql.com/doc/x-devapi-userguide/en/database-connection-example.html有一个用于 C++的示例

var mySession = MySQLX.GetSession("server=localhost;port=33060;user=user;password=password;");


推荐阅读