zoukankan      html  css  js  c++  java
  • 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 ~]#
  • 相关阅读:
    mysql 主从复制
    confluence wiki搭建使用
    python 解析json loads dumps
    在linux下修改mysql的root密码
    [转]量子恒道统计
    php include
    php solr 查询
    php solr 扩展
    IKAnalyzer 和 solr4.3 冲突
    solr 4.3.0 配置
  • 原文地址:https://www.cnblogs.com/Robotke1/p/3050123.html
Copyright © 2011-2022 走看看