下面贴出我在实际工作中遇到mysql操作数据表的sql命令,如有不对的地方,请多指教:

c++链接mysql头文件命令
g++ is_in_polygon.cpp -o is_in_polygon -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient eclipse 设置mysql
project->setting->properties->tool settings->libraries-libraries(l) write into:mysqlclient. project->properties->tool settings->libraries->libraries search path write into:/usr/lib/mysql.
project->properties->c/c++ build->environment->cplus_include_path and c_include_path 加入:/usr/include/mysql 建立数据表
use test;
create table test_info (
id integer not null,
content varchar(64) not null,
primary key (id)
); delete from test_info;
insert into test_info values (2010, 'hello, line
suped
seped
"end'
); 向数据表导入数据
load data local infile '/tmp/test.csv' into table test_info fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n'; 增加列
alter table t_icf_day add new_field_id int(5);
alter table t_icf_day add column day_id BIGINT primary key auto_increment; 设主键
alter table userinfo add prmariy key (userId); 删除表
drop table
drop table if exits '%s_T_ICF_HIST_DATE' 删除列
alter table t2 drop column c; 查找不重复的数据
insert into T_ICF_HIST_D select a.* from China_t_icf_hist_d a,(select c_gouki,c_kisyu,count(*) from %s_T_ICF_DAY group by c_gouki,c_kisyu having count(*)>=1) as b where a.c_gouki=b.c_gouki and a.c_kisyu=b.c_kisyu;", 重命名列
alter table t1 change a b integer; 改变列的类型
alter table t1 change b b bigint not null;
alter table infos change list list tinyint not null default '0'; 重命名表
alter table t1 rename t2; 多表查询
select c.nom, e.nom from consultant c, affaire a, besoin b, salarie sa, site s, entreprise e
where c.consultant_id=a.consultant_id and a.besoin_id=b.besoin_id and b.salarie_id=sa.salarie_id and sa.site_id=s.site_id and s.entreprise_id=e.entreprise_id 插入符合条件的列
insert into gansu_icf_hist_d select b.* from gansu_t_icf_day a, T_ICF_HIST_D b where a.c_kisyu=b.c_kisyu and a.c_gouki=b.c_gouki;
insert into gansu_day select a.* from t_icf_day a, gansu_gis_convert_result b where a.d_hassei=b.d_hassei and a.c_gouki=b.c_gouki; 查询后,插入表中
insert into gansu_gis_convert_result SELECT * FROM t_gis_convert_result_icf_other where nv_place='GANSU, China'; 向表中添加数据
1 insert into employee values (’200301’,’zhangsan’,’m’,’1978/5/8’);
2 insert into employee values (’200302’,’lisi’,’f’,’1973/3/20’); 创建索引
1 create table test1 (test1_id char(4),name char(20), index idx_test1(name(10)));
2 create index idx_employee on employee(name); 用create为name列创建索引 察看索引
1 show index from employee;
2 show index from products; 删除索引
drop index idx_employee on employee;
alter table products drop index idx_products; 查看代码
select * from gansu_day group by c_kisyu and d_hassei and c_gouki having count(*) > 1; 多表查询
insert into yunnan_gis_convert_result SELECT * FROM t_gis_convert_result_icf_AWS where nv_place='YUNNAN, China' union all
SELECT * FROM t_gis_convert_result_icf_AXA_AWU where nv_place='YUNNAN, China' union all SELECT * FROM t_gis_convert_result_icf_other where nv_place='YUNNAN, China';
insert into LIAONING_T_ICF_HIST_D select a.* from China_t_icf_hist_d a,(select c_gouki,c_kisyu,count(*) from LIAONING_T_ICF_DAY group by c_gouki,c_kisyu having count(*)>=1) as b where a.c_gouki=b.c_gouki and a.c_kisyu=b.c_kisyu; 远程访问数据库 http://hi.baidu.com/andycai/blog/item/5c8dabcc97fa931701e9281f.html
http://blog.csdn.net/uixor_/article/details/6762194

其实直接看mysql的syntax就可以,不过没有这样直观。

下面给出c++链接mysql语句

MYSQL_RES *Querysql(char *sql) {
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";/*服务器名*/
char *user = "root";/*用户名*/
char *password = ""; /* 此处改成你的密码 */
char *database = "EserviceDB";/*数据库名*/
MYSQL *conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
return res;
}
/* send SQL query */
if (mysql_query(conn, sql)) {//sql语句
fprintf(stderr, "%s\n", mysql_error(conn));
return res;
}
res = mysql_store_result(conn);//保存查询结果
mysql_close(conn);
return res;
}

这个函数主要用来链接数据库,返回带有数据格式为:MYSQL_RES,主要用于查询操作:

void NoQuery(char *sql) {
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";/*服务器名*/
char *user = "root";/*用户名*/
char *password = ""; /* 此处改成你的密码 */
char *database = "EserviceDB";/*数据库名*/
MYSQL *conn = mysql_init(NULL);
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
printf("the connection fail!");
}
if (mysql_query(conn, sql)) {//sql语句
fprintf(stderr, "%s\n", mysql_error(conn));
printf("the query fail!");
} else
printf("query insert sql sucess");
mysql_close(conn);
}

MySQL 常用命令大全2的更多相关文章

  1. MySQL 常用命令大全

    Mysql常用命令行大全 第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键 ...

  2. mysql常用命令大全 mysql常用命令总结

    原文地址:http://www.jbxue.com/db/12472.html 本文介绍下,mysql中常用的一些命令,包括创建与修改数据库.数据库中的表,mysql的权限管理命令grant.revo ...

  3. Mysql常用命令大全 sql

    1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...

  4. MySQL常用命令大全(转)

    下面是我们经常会用到且非常有用的MySQL命令.下面你看到#表示在Unix命令行下执行命令,看到mysql>表示当前已经登录MySQL服务器,是在mysql客户端执行mysql命令. 登录MyS ...

  5. Mysql常用命令大全

    1.连接Mysql 格式: mysql ­h主机地址 ­u用户名 -p用户密码 2.1 创建数据库 命令:create database <数据库名> 例1:建立一个名为xhkdb的数据库 ...

  6. [批处理教程之MySQL]001.MySQL 常用命令大全

    连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MySQL 首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root -p ...

  7. php开发面试题---Mysql常用命令行大全

    php开发面试题---Mysql常用命令行大全 一.总结 一句话总结: 常见关键词:create,use,drop,insert,update,select,where ,from.inner joi ...

  8. Ubuntu常用命令大全 以及 PHP+MySQL代码部署在Linux(Ubuntu)上注意事项

    PHP+MySQL代码部署在Linux(Ubuntu)上注意事项 https://cloud.tencent.com/developer/article/1024187 Ubuntu常用命令大全 ht ...

  9. Ubuntu常用命令大全(转)

    点评:Ubuntu常用命令大全,学习ubuntn系统的朋友可以收藏下,用ctrl+F查找即可 一.文件/文件夹管理 ls 列出当前目录文件(不包括隐含文件) ls -a 列出当前目录文件(包括隐含文件 ...

随机推荐

  1. s3c2440 的 rtc 操作

    实时时钟(RTC)其主要功能是电源故障的制度下,使用后备电源,时钟继续.为了不浪费时间信息. s3c2440内部集成了RTC模块,并且用起来也十分简单. 其内部的寄存器BCDSEC,BCDMIN,BC ...

  2. 深入struts2.0(五)--Dispatcher类

    1.1.1       serviceAction方法 在上个Filter方法中我们会看到例如以下代码: this.execute.executeAction(request, response, m ...

  3. Android 数据库加密

    一 一个简短的引论   SQLite是一个轻量的.跨平台的.开源的数据库引擎.它的读写效率.资源消耗总量.延迟时间和总体简单性上具有的优越性,使其成为移动平台数据库的最佳解决方式(如Android.i ...

  4. 将字符串“abc”全排列成:abc、acb、bac、bca、cab、cba

     [STAThread]         static void Main()         {             string s = "abcd";           ...

  5. 关于重写ID3 Algorithm Based On MapReduceV1/C++/Streaming的一些心得体会

    心血来潮,同时想用C++连连手.面对如火如荼的MP,一阵念头闪过,如果把一些ML领域的玩意整合到MP里面是不是很有意思 确实很有意思,可惜mahout来高深,我也看不懂.干脆自动动手丰衣足食,加上自己 ...

  6. PHP 做 RSA 签名 生成订单(支付宝例子)

    /组合签名 $a=time(); $b=substr($a, 1); //生成随机订单号 $orderid= $b.mt_rand(10000,99999); //合作身份者id,以2088开头的16 ...

  7. YII相关资料(干货)

    Sites 网站 yiifeed:Yii 最新动态都在这里 yiigist:Yii 专用的 Packages my-yii:Yii 学习资料和新闻 Docs 文档 Yii Framework 2.0 ...

  8. PHP学习笔记----IIS7下安装配置php环境

    原文:PHP学习笔记----IIS7下安装配置php环境 Php如何安装 Php版本的选择 Php在windows下的(php5.4.7)有两种版本: VC9 x86 Non Thread Safe ...

  9. (UML两个汇总)九种图。

    最后总结UML关系,有明确的关系,现在让我们总结一下UML九图..图往往比文字要直观,因此,当我们开发软件.文件必须是不可或缺的人物,. 以下我将这九种图分了一下: 我们还能够将这九种图分为静态图和动 ...

  10. 自己写CPU第九阶段(5)——实现负载存储指令2(改变运行阶段)

    我们会继续上传新书<自己动手写CPU>.今天是第42篇.我尽量每周四篇,可是近期已经非常久没有实现这个目标了,一直都有事.不好意思哈. 开展晒书评送书活动,在q=%E4%BA%9A%E9% ...