MySQL编程删除某个元组

mysql> use test;
Database changed
mysql> select * from student;
+------+------+
| Id   | name |
+------+------+
|   29 | Mike |
|   12 | Lili |
+------+------+
2 rows in set (0.00 sec)

mysql> quit
Bye
[root@localhost ~]#

源文件mysql.c如下:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <unistd.h>
 5 #include <sys/types.h>
 6 #include <dirent.h>
 7 #include "/usr/local/mysql/include/mysql.h"
 8 
 9 const char* host = "127.0.0.1";
10 MYSQL* mysql;
11 const char* user = "root";
12 const char* password = "";
13 
14 int main(int argc ,char **argv)
15 {
16         int t, r;
17 
18         mysql = mysql_init(mysql);
19         mysql = mysql_real_connect(mysql, host, user, password, "test", 0, NULL, 0);
20 
21         if (!mysql)
22         {
23                 perror("MySQL connect error!\n");
24                 return EXIT_FAILURE;
25         }
26 
27         if (mysql_query(mysql, "delete from student where Id=29"))  // 删除Id=29的那个元组
28         {
29                 perror("MySQL query error!\n");
30                 return EXIT_FAILURE;
31         }
32 
33         mysql_close(mysql);
34 
35         return 0;
36 }

[root@localhost ~]# gcc mysql.c -g -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient
[root@localhost ~]# ./a.out

mysql> use test;
Database changed
mysql> select * from student;
+------+------+
| Id   | name |
+------+------+
|   12 | Lili |
+------+------+
1 row in set (0.00 sec)

mysql> quit
Bye
[root@localhost ~]#

 

转载于:https://www.cnblogs.com/Robotke1/archive/2013/04/28/3050123.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值