数据库
1、 查看所有数据库:show databases;
2、 查看指定数据库编码集:show create database xxx;
3、 删除指定数据库:drop database xxx;
4、 修改数据库编码集:alter database xxx character set utf-8;
5、 切换数据库:use xxx;
6、 查看当前正在使用的数据库:select database();
表结构
- 查询
①查看表结构:desc xxx;
②查询所有表:show tables;
- 增加
①在已有表结构添加一列:alter table 表名 add 列名 类型(长度) 约束;
- 修改
①改变已有表结构某列类型:alter table 表名 modify 列名 类型(长度) 约束;
②修改已有表结构列名:alter table 表名 change 旧列名 新列名 类型(长度) 约束;
③修改表名:修改表名:alter table 旧表名 rename to 新表名;
④给表添加约束:alter table 表名 add UNIQUE KEY uniq_xxx
(id
,name
);
⑤添加新列:alter table 表名 add column 列名 varchar(30);
⑥修改列名: alter table 表名change column 旧列名 新列名 varchar(30);
⑦修改列属性:alter table 表名 modify 列名 varchar(22);
- 删除
①删除已有表结构一列:alter table 表名 drop 列名;
②删除表:drop table 表名;
③删除列:alter table 表名 drop column 列名;
表数据
- 增加
①insert into 表名(列名1,列名2…) values (值1,值2…) - 删除
①delete from 表名 where xxx=xxx; - 修改
①update 表名 set 列名=xxx where xxx=xxx; - 查询
①查询所有数据:select * from 表名;
②查询某一列不重复的数据类型:select distinct 列名 from 表名;
③查询的同时计算出来:select name,math+english+chinese as sum from 表名;
④不等于:select * from 表名 where 列名<> 90;
⑤等于集合:select * from 表名 where 列名 in (70,80,90);
⑥null:select * from 表名 where 列名 is null;
⑦排序:select * from 表名 order by 列名 asc;
⑧统计个数:select count(*) from 表名 where xxx=xxx;
⑨计算列的总和:select sum(math),sum(english) from 表名;
⑩计算列的平均值/最大值:select avg(math),max(english) from 表名;
外键约束
alter table 表名 add foreign key(列名) references 表名(列名)
eg:将student的id关联到student_score_bind的student_id
student表
student_score_bind表
alter table student_score_bind add foreign key(student_id) references student(id);
查看配置的参数详细信息
show create table student
select * from sdn_slb_listeners a where (a.load_balancer_id,a.protocol_port) in (select load_balancer_id,protocol_port from sdn_slb_listeners group by load_balancer_id,protocol_port having count(*) > 1);