www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Mellanox InfiniBand卡线缆性能延迟性测试程序源码,C源码实现操作mysql库,实现简单的增删改查,代码当前用的是增插入20000条数据

具体见源码

 1 #include <mysql/mysql.h>
 2 #include <time.h>
 3 #include <stdio.h>
 4 //gcc $0 -L /usr/lib64/mysql/ -lmysqlclient -o outputname
 5 //Mellanox InfiniBand Card Perforce test,By yodoo ruiy
 6 //
 7 
 8 void insert() {
 9 MYSQL      *conn;
10 MYSQL_RES  *res;
11 MYSQL_ROW  row;
12 
13 char *server = "192.168.3.205";
14 char *user = "root";
15 char *password = "123"; /* set me first */
16 char *database = "ruiy";
17 //char *query = "select * from user";
18 //char *query = "insert into perforce values("rui_C","rui_S","rui_N","rui_v","rui_O","rui_U","rui_T","rui_S","rui_CO","rui_All");";
19 //char *query = "insert into perforce values('rui_C','rui_S','rui_N','rui_v','rui_O','rui_U','rui_T','rui_S','rui_CO','rui_All');"
20 char *query = "insert into perforce values(\"rui_C\",\"rui_S\",\"rui_N\",\"rui_v\",\"rui_O\",\"rui_U\",\"rui_T\",\"rui_S\",\"rui_CO\",\"rui_All\")";
21 int t,r;
22 
23 conn = mysql_init(NULL);
24 
25 if(!mysql_real_connect(conn,server,user,password,database,0,NULL,0))
26 {
27 printf("Error connecting to database: %s\n", mysql_error(conn));
28 }
29 else
30 {
31 printf("Connected....\n");
32 }
33 
34 t = mysql_query(conn, query);
35 
36 if(t)
37 {
38 printf("Error making query: %s\n", mysql_error(conn));
39 }
40 else
41 {
42 printf("Query made...\n");
43 res = mysql_use_result(conn);
44 if(res)
45 {
46 for(r=0; r<=mysql_field_count(conn); r++)
47 {
48 row = mysql_fetch_row(res);
49 if(row<0) break;
50 for(t=0; t<mysql_num_fields(res); t++)
51 printf("%s", row[t]);
52 printf("\n");
53 }
54 }
55 mysql_free_result(res);
56 }
57 mysql_close(conn);
58 }
59 
60 void Ptime()
61 {
62 FILE *fp;
63 time_t now;
64 struct tm *timenow;
65 time(&now);
66 timenow = localtime(&now);
67 fp = fopen("time.xml","a+");
68 fprintf(fp,"%s",asctime(timenow));
69 fclose(fp);
70 }
71 
72 
73 main()
74 {   Ptime();
75     int i;
76     for (i=0;i<20000;i++)
77     insert();
78     Ptime();
79     return 0;
80 }

 

 

posted on 2014-01-07 13:36  秦瑞It行程实录  阅读(467)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui