创建库
create database xxx;
查看库名
show databases;
进入库
use xxx;
查看表
show tables;
创建表
create tables xxx;
清除表
delete from xxx;
查看表结构
describe xxx;
创建表名 写有id xm xb csny
create table name (
id int(3) auto_increment not null primary key,
xm char(8) not null,
xb char(2) ,
csny date);
写入记录
insert into 表名(字段,字段) values('记录','记录');
insert into 表名(字段) values('记录');
验证是否写入正确
select * from xxx;
修改记录
update xxx set csny='2009-2-23' where xm='张三';
删除表记录
delete from 表名 where 字段='xxx';
删除表
drop table xxx;
alter table 表名 change 字段 字段 类型
修改表字段类型
例如alter table student change name name char(20);
16.删除表字段的值,可以将所有值清空:
UPDATE table_name SET field_name = '';
如果不清空而是修改成别的值:
UPDATE 表名 SET 表字段 = '羽毛球';
17.表添加第一列字段
alter table zhm add name char(20) first;
因为添加完,默认的值是null
所以要更新这默认值
18.表内容检索范围
select * from 表名 where 字段名 范围 and 字段名 范围
select * from 表名 where age>=21 and age<=23;
19.通配符检索 根据字符数检索
例如 name jerry kerry
select * from 表名 where 表字段名 like '_需要检索的';
select * from 表名 where name like '_erry';
因为_代表一个字符
如果要检索的是 字符有4个 我们检索的是第三个为0
例如 salary 8000 9000 7080
select * from 表名 where salary like '__0_'; (0前面有两条下划线,代表两个字符,这样就是4个字符)
20.检索以X开头的,其余字符任意长度
select * from 表名 where salary like '8%';
检索任意开头,中间有0,后面都是任意的
select * from 表名 where salary like '%0%';
21.选择性检索
select * from money where age >20 and salary >8000;
选择性检索
select * from money where age in(20,21);
22.alter删除主键约束
alter table temp drop primary key;
alter添加主键
alter table temp add primary key(name, pwd);
alter修改列为主键
alter table temp modify id int primary key;
23.设定条件查找值
查找 表名 字段名 字段名>数字
select * from book group by name having pagecount>300
24.建立索引(index)
create index idx(添加索引名,免混淆)_Customer(表名)_last_name(字段名) on Customer(last_name);
create index idx_Customer_location on Customer(City,Country);
25.展示索引(表名)
show index from Customer;
26.查看复合索引内容
show index from Customer\G;
27.唯一性索引(unique)
1.alter table Customer change First_Name First_Name char(50) unique;
2.create unique index idx_Customer_First_Name on Customer(First_name);
28.删除表格内容,却保留表格
truncate table 表名;
29.union 表格和表格之间共同字段名查找合并
select 字段名 from 表名 union select 字段名 from 表名
30.查看当前正在使用的二进制日志文件
show master status;
31.查看二进制日志文件
show binlog events in '二进制日志文件';
32.查看二进制日志文件内容
mysqlbinlog mysql-bin.000006 二进制文件名