bitsCN.com
下面贴出我在实际工作中遇到mysql操作数据表的sql命令,如有不对的地方,请多指教:
c++链接mysql头文件命令 g++ is_in_polygon.cpp -o is_in_polygon -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclienteclipse 设置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 tabledrop 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 allSELECT * 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);}

该函数主要用来插入,删除,添加功能。
bitsCN.com
在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

MySQL是一种常见的关系型数据库,是许多网站和应用程序的核心组件。随着数据量越来越大,如何优化MySQL的性能就变得尤为重要。其中一个关键领域是数据表的压缩,在本文中我们将介绍MySQL中的数据表压缩技术。压缩表和非压缩表MySQL中有两种类型的数据表:压缩表和非压缩表。非压缩表是MySQL默认的表类型,它使用固定长度的行格式,对数据进行存储。这意味着数据

在mysql中,可利用“ALTER TABLE 表名 DROP INDEX unique key名”语句来删除unique key;ALTER TABLE语句用于对数据进行添加、删除或修改操作,DROP INDEX语句用于表示删除约束操作。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,是否需要commit取决于存储引擎:1、若是不支持事务的存储引擎,如myisam,则不需要使用commit;2、若是支持事务的存储引擎,如innodb,则需要知道事务是否自动提交,因此需要使用commit。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),