我写c++做30000*30000查询MySQL插入
例子
for(i=0;i<30000*30000;i++){
// do the MySQL insert
call the function to insert code (maybe just query insert the i value)
}
我正在使用 mysqlsart()
和 mysqlclose()
子函数
void mysqlstart()
{
//MYSQL *conn_ptr;
conn_ptr = mysql_init(NULL);
if(!conn_ptr)
{
fprintf(stderr,"mysql_init failed\n");
//return EXIT_FAILURE;
}
conn_ptr = mysql_real_connect(conn_ptr,"localhost","root","nlpgroup","testdb",0,NULL,0);
}
void mysqlclose()
{
mysql_close(conn_ptr);
}
我第一次像这样调用函数
mysqlstart();
for loop
mysqlclose();
一开始会很好,几天后我发现错误:MySQL 服务器已经消失
并从互联网上找到一些解决方案,可能会更改 max_allowed_packet 或其他...
而且我不知道什么是适合 30000*30000 的设置
我想知道有什么我可以改变我的代码或加快查询速度的方法
最佳答案
您可以通过这种方式一次插入多行
http://dev.mysql.com/doc/refman/5.5/en/insert.html
INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example:
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
关于php - 使用 MySQL 提高大型查询插入性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26795782/