gpt4 book ai didi

C++ ,Mysql API 加载数据本地

转载 作者:行者123 更新时间:2023-11-29 19:06:31 25 4
gpt4 key购买 nike

我需要使用 mysql_query("LOAD DATA LOCAL") 将数据加载到远程数据库。数据格式如下:

460022103337063 8615210477725

但不幸的是,从文件加载时总是出现coredump。客户端库是 mysql-connector-c-6.0.2-linux-sles10-x86.tar.gz,这是来自 dev.mysql.com/download 的最新版本。我们将使用 libmysql.so.16.0.0。我的代码如下:

m_pMySQL = mysql_init(NULL);
if(!m_pMySQL)
{
A7C_LOG_ERROR (logCat, "Can not init mysql!");
return STATUS_ERROR;
}
if(0 != mysql_options(m_pMySQL, MYSQL_OPT_LOCAL_INFILE, 0))
{
A7C_LOG_ERROR (logCat, "Can not set mysql to local infile !");
}

if(!mysql_real_connect(m_pMySQL,
m_host.c_str(),
m_username.c_str(),
m_password.c_str(),
m_dbname.c_str(),
m_port,
NULL,
//0))
CLIENT_MULTI_RESULTS|CLIENT_LOCAL_FILES))
{
A7C_LOG_ERROR (logCat, "Can not connect mysql server. ERROR: "<<mysql_error(m_pMySQL));
return STATUS_ERROR;
}

string load("LOAD DATA LOCAL INFILE '/var/tmp/TDR_HTU1_TID01' IGNORE INTO TABLE LOOKUP");
if(mysql_query(m_pMySQL, load.c_str()))
{
A7C_LOG_ERROR (logCat, "Failed to load. Statement: "
<<load<<". Error:"<<mysql_error(m_pMySQL));
return STATUS_ERROR;
}

gdb 的核心信息:

> Program terminated with signal 11, Segmentation fault.
> #0 0xf7b362d1 in my_read (Filedes=18,
> Buffer=0xf3645a40 "460001191124402\t8613611226646\n460027014803029\t8618701483175\n460028101539830\t8615810184408\n460020264337590\t8613426218170\n460022102200877\t8615210220922\n460023100016582\t8615010067740\n460021537608606\t8615"...,
> Count=8192, MyFlags=<value optimized out>) at
> /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c:55
> 55
> /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c:
> No such file or directory.
> in /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c
> (gdb) where
> \#0 0xf7b362d1 in my_read (Filedes=18,
> Buffer=0xf3645a40 "460001191124402\t8613611226646\n460027014803029\t8618701483175\n460028101539830\t8615810184408\n460020264337590\t8613426218170\n460022102200877\t8615210220922\n460023100016582\t8615010067740\n460021537608606\t8615"...,
> Count=8192, MyFlags=<value optimized out>) at
> /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/mysys/my_read.c:55
> #1 0xf7ac513d in default_local_infile_read (ptr=0xf3d59190,
> buf=0xf3645a40 "460001191124402\t8613611226646\n460027014803029\t8618701483175\n460028101539830\t8615810184408\n460020264337590\t8613426218170\n460022102200877\t8615210220922\n460023100016582\t8615010067740\n460021537608606\t8615"...,
> buf_len=8192) at
> /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:693
> #2 0xf7ac5337 in handle_local_infile (mysql=0x80aa6c0, net_filename=0x80add11 "/var/tmp/TDR_HTU1_TID01") at
> /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:577
> #3 0xf7ac0532 in cli_read_query_result (mysql=0x80aa6c0) at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/client.c:2867
> #4 0xf7abcc04 in mysql_real_query (mysql=0x80aa6c0, query=0x807c2d4 "LOAD DATA LOCAL INFILE '/var/tmp/TDR_HTU1_TID01' IGNORE INTO TABLE
> LOOKUP", length=73)
> at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/client.c:2912
> #5 0xf7ac4f75 in mysql_query (mysql=0x80aa6c0, query=0x807c2d4 "LOAD DATA LOCAL INFILE '/var/tmp/TDR_HTU1_TID01' IGNORE INTO TABLE LOOKUP")
> at /export/home2/tmp/cteam/bs/connector-c/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:790

如果我改用mysql的命令行客户端,效果很好。这阻碍了我们的项目。请帮忙!

最佳答案

需要更改 libmysqlclient 版本,它将在 libmysqlclient.so.16 版本中工作。它在 libmysqlclient.so.18 版本中不起作用。

关于C++ ,Mysql API 加载数据本地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43447232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com