MySQL 常用命令大全2
下面贴出我在实际工作中遇到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的更多相关文章
- MySQL 常用命令大全
Mysql常用命令行大全 第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键 ...
- mysql常用命令大全 mysql常用命令总结
原文地址:http://www.jbxue.com/db/12472.html 本文介绍下,mysql中常用的一些命令,包括创建与修改数据库.数据库中的表,mysql的权限管理命令grant.revo ...
- Mysql常用命令大全 sql
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- MySQL常用命令大全(转)
下面是我们经常会用到且非常有用的MySQL命令.下面你看到#表示在Unix命令行下执行命令,看到mysql>表示当前已经登录MySQL服务器,是在mysql客户端执行mysql命令. 登录MyS ...
- Mysql常用命令大全
1.连接Mysql 格式: mysql h主机地址 u用户名 -p用户密码 2.1 创建数据库 命令:create database <数据库名> 例1:建立一个名为xhkdb的数据库 ...
- [批处理教程之MySQL]001.MySQL 常用命令大全
连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MySQL 首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root -p ...
- php开发面试题---Mysql常用命令行大全
php开发面试题---Mysql常用命令行大全 一.总结 一句话总结: 常见关键词:create,use,drop,insert,update,select,where ,from.inner joi ...
- Ubuntu常用命令大全 以及 PHP+MySQL代码部署在Linux(Ubuntu)上注意事项
PHP+MySQL代码部署在Linux(Ubuntu)上注意事项 https://cloud.tencent.com/developer/article/1024187 Ubuntu常用命令大全 ht ...
- Ubuntu常用命令大全(转)
点评:Ubuntu常用命令大全,学习ubuntn系统的朋友可以收藏下,用ctrl+F查找即可 一.文件/文件夹管理 ls 列出当前目录文件(不包括隐含文件) ls -a 列出当前目录文件(包括隐含文件 ...
随机推荐
- 修改vim/terminal配色
http://blog.csdn.net/angle_birds/article/details/11694325
- android 如何加入第一3正方形lib图书馆kernel于
注意:只能lib图书馆kernel编译到位.例如下列: alps/kernel/ alps/mediatek/custom/common/kernel/ alps/mediatek/custom/$p ...
- MVC生成CheckBoxList并对其验证
原文:MVC生成CheckBoxList并对其验证 通过扩展方法,可以让CheckBox水平排列,生成CheckBoxList,正如"MVC扩展生成CheckBoxList并水平排列&quo ...
- 一步一步写算法(之prim算法 中)
原文:一步一步写算法(之prim算法 中) [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] C)编写最小生成树,涉及创建.挑选和添加过程 MI ...
- W5500问题集锦(一)
在"WIZnet杯"以太网技术竞赛中,有非常多參赛者在使用中对W5500有各种各样的疑问,对于这款WIZnet新推出的以太网芯片,使用中大家是不是也一样存在下面问题呢?来看一看: ...
- JavaScript继承基础讲解,原型链、借用构造函数、混合模式、原型式继承、寄生式继承、寄生组合式继承
说好的讲解JavaScript继承,可是迟迟到现在讲解.废话不多说,直接进入正题. 既然你想了解继承,证明你对JavaScript面向对象已经有一定的了解,如还有什么不理解的可以参考<面向对象J ...
- [Android] Volley源代码分析(五岁以下儿童)Q \\ u0026一个
Volley源代码分析系列那里一段时间,告诉我,有许多私人留言,同时一些问题抛出.对于一些简单的问题,我们跳,这两天被连接到朋友@smali提出的问题.告诉我你不得不赞叹查看源代码时的详细程度,大家一 ...
- Linux下使用cat制作“内涵图”
http://blog.csdn.net/odaynot/article/details/7939869
- idea中ajax中文乱码
case:@RequestMapping中添加 produces= "text/plain;charset=UTF-8", @RequestMapping(method = Req ...
- FileOutputStream字节输出流和FileInputStream输入流(切记:out是输出到本地中,in是输入到程序中)这里介绍大文件和小文件的读取方式
//FileOutputStream public class FileOutputStreamDemo { /**字节流:适用于任何文件,以字节为单位,进行读写操作 *字节流操作步骤: *1.创 ...