#include <iostream>
#include <winsock2.h>
#include <string>
#include "mysql.h"
#pragma comment (lib, "Libmysql.lib");
using namespace Std;
int main ()
{
MySQL MySQL;
Mysql_init (&mysql); Initialization
MYSQL *connstatus = Mysql_real_connect (&mysql, "localhost", "root", "", "Sky", 3306,0,0);
if (Connstatus = = NULL)
{
Connection failed
int i = Mysql_errno (&mysql);
String strerror= mysql_error (&mysql);
cout << "Error info:" <<strError<<endl;
return 0;
}
cout<< "Mysql Connected ..." <<endl;
String strSQL;
Mysql_res *result=null; Data result set
Insert operation
strSQL = "INSERT INTO T1 values (2, ' lyb ')";
mysql_query (&mysql, "START TRANSACTION"); Turn on the transaction, and if the transaction is not turned on, then the efficiency becomes very low!
for (int i=0; i<10000; i++)
{
mysql_query (&mysql,strsql.c_str ());
}
mysql_query (&mysql, "COMMIT"); Commit a transaction
cout<< "Insert End" <<endl;
Releasing the result set close the database
Mysql_free_result (result);
Mysql_close (&mysql);
Mysql_library_end ();
return 0;
}
C + + operation MySQL Large data insertion inefficient solution