Mysql 笔记
1. 管理
1.1 登录
mysql -u root -p;
1.2 改密
set password root@localhost = password('xxxxx');
1.3 创建索引
create [unique] index idxna me no tabname(col...);
1.4 删除索引
drop index idxname;
2. 增
2.1 创建数据库
create database xxx;
2.2 使用数据库
use database_xxx;
2.3 查看数据库
show databases;
2.4 查看数据表
show tables;
2.5 创建数据表
CREATE TABLE xxx(id int(11) AUTO_INCRERMENT,
name varchar(30),
hp float,
damage int(11),
PRIMARY KEY(id)
)DEFAULT T CHARTSET=utf-8;
2.6 插入数据
insert into xxx_table values(xxx,xxx,xxx,xxx);
3. 删
3.1 删除数据库
drop database xxx;
3.2 删除数据表
delete from xxx where id=x;
4. 改
4.1 修改数据
update xxx set xx=xxx where xx=x;
update hero set hp =100 where id =1;
5. 查
5.1 查询所有数据
select * from xxx;
5.2 统计表中数据
select count(*) from xxx;
5.3 分页查询
显示前5条数据
select * from xxx limit 0,5;
6.表
6.1 约束
-
PK
primer key
主键- 每行元素==独一无二==标识
- 不能有空值
- 每个表只能有==一个==主键
- 由一列或者多列组成
-
NN
not null
非空 -
UQ
unique
唯一- 该项数据==不能重复==
- 允许一条可以为==NUL==L
-
B
binary
二进制数据 -
UN
unsigned
无符号 -
ZF
zero fill
填充0 -
AI
auto increment
自增 -
G
generated
生成列
6.2 关系
OneToOne
一对一OneToMany
一对多ManyToMany
多对多
6.3 外键关联
- 未完待续