==============新建数据库============create database if not exists XXX;==============删除数据库============drop database if exists XXX;==============新建表================create table if not exists z_class(z_id int UNSIGNED auto_increment,z_name VARCHAR(100) NOT NULL,z_age INT NOT NULL,z_date date,PRIMARY KEY(z_id))ENGINE=INNODB DEFAULT charset=utf8;==============插入数据=============insert into XXX(,,,)values(,,,),(,,,),(,,,);==============复制数据=============create table XXX2 like XXX1; 复制表结构insert into XXX2 select * from XXX1; 复制数据==============删除数据=============delete from XXX where id=y;============删除全部数据===========delete from XXX;============排序删除数据===========delete from XXXorder by xxxlimit 2;==============更新数据=============update XXXset xxx = ywhere id = z;============多表更新数据===========update XXX1 set x01 =(select y01 from XXX2where y02 = 'y'order by rand()limit 1) where x02 is null;===========修改表结构属性==========alter table XXX1change column xxxxxx int(10) not null;===========添加表结构属性==========alter table XXX1add column info varchar(10) nullafter xxx01;===========删除表结构属性==========alter table XXX1drop column xxx01;===========修改表名称属性==========alter table XXX1rename to XXX2;或者rename table XXX1 to XXX2;==============查询数据=============select * from XXX1 where xxx01 <= 3;模糊查询:select * from XXX1where xxx01 like '%o'排序:select * from XXX1 order by xxx01select * from XXX1 order by xxx01 desc聚合:select sum(xxx01),xxx02 from XXX1 group by xxx02平均值:select avg(xxx01) from XXX1合计:select sum(xxx01) from XXX1最大:select max(xxx01) from XXX1最小:select min(xxx01) from XXX1合计总行数:select count(xxx01) from XXX1分组查询sal字段的最大值:id,sal,numselect max(sal),num from XXX1 group by num查询之间的数:select * from XXX1 where between 1 and 3查询指定行的数据:select * from XXX1 limit 3,2 不包含第三行,向下查询2行(4,5行)查询表结构:desc XXX1创建视图:create view st as select * from XXX1 where xxx01 = 'x'删除视图:drop view st