mysql C++ connector [mysql-connector-c++-8.0.19-linux-glibc2

mysql C++ connector [mysql-connector-c++-8.0.19-linux-glibc2.12-x86-64bit]

本文关键字:19-linux-glibc2 mysql-connector-c++-8 C++ connector mysql      更新时间:2023-10-16

我的应用程序崩溃了:

static sql::Driver *driver=get_driver_instance();
shared_ptr<sql::Connection> con(driver->connect("127.0.0.1:3306","asif", "password"));
con->setSchema("asif");  //it crashes here (segv)

代码直接来自 mysql C++连接器相关站点上提供的示例

我有模式,好像

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| CREBACO            |
| asif               |
| asif1              |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
8 rows in set (0.00 sec)
mysql> use asif;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_asif |
+----------------+
| tab1           |
| tab2           |
+----------------+
2 rows in set (0.00 sec)

调试时:

#0  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:371
#1  0x00007ffff7301c80 in std::string::append(std::string const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x00007ffff7634efe in sql::SQLString::append (str=..., this=0x7fffffffdc10)
at /export/home/pb2/build/sb_0-32258110-1547655664.03/mysql-connector-c++-1.1.12/cppconn/sqlstring.h:155
#3  sql::mysql::MySQL_Connection::setSchema (this=0x55555578bed0, catalog=...)
at /export/home/pb2/build/sb_0-32258110-1547655664.03/mysql-connector-c++-1.1.12/driver/mysql_connection.cpp:1345
#4  0x000055555555585d in main () at ../Crebaco/main.cpp:25

来自GDB的调用堆栈,我在mysql-connector-c ++ -1.1.12中遇到相同的错误

代码非常简单(这不是答案(,你能试试这段代码连接到你的MYSQL实例吗

//export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/asif/Desktop/QT/Crebaco/mysql-connector-c++-8.0.19-linux-glibc2.12-x86-64bit/lib64
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
using namespace std;
#define SERVERSTRING "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "password"
#define DATABASE "test"
int main()
{
cout<<"Content-Type: application/txtrnrn";
try {
static sql::Driver *driver=get_driver_instance();
shared_ptr<sql::Connection> con(driver->connect("127.0.0.1:3306","asif", "password"));
con->setSchema("asif");
shared_ptr<sql::Statement> stmt(con->createStatement());
shared_ptr<sql::ResultSet> res(stmt->executeQuery("select * from tab1"));
while (res->next()) {
cout << res->getString("name") << endl;
}
}catch(sql::SQLException &e)
{
cout << "# ERR: " << e.what()<<endl;
cout << "MySQL error code: " << e.getErrorCode()<<endl;
//cout << ", SQLState: " << e.getSQLState()<<endl;
}
return 0;
}