Home Database Mysql Tutorial mysqlsql命令大全_MySQL

mysqlsql命令大全_MySQL

Jun 01, 2016 pm 01:18 PM
mysql data sheet

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
Copy after login

其实直接看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;}
Copy after login
复制代码

这个函数主要用来链接数据库,返回带有数据格式为: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);}
Copy after login
复制代码

该函数主要用来插入,删除,添加功能。

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

See all articles