Mysql复习秘籍

来源:互联网 发布:晨曦造价软件 编辑:程序博客网 时间:2024/06/05 00:27

#基础知识
1. 数据库的连接
mysql -u rootgod -p root -h 127.0.01
2. 库 知识
- show database
- use datebase
- create datebase dbname charset utf-8
- drop datebase dbname
3. 表操作
- show tables
- desc tableName (查看表结构)
- show create table tablename
- create table user(
id int auto_increment,
name varchar(20) not null default ”,
age tinyint unsigned not null default 0,
index id(id)
)engine=innodb charset=utf8;
- alter table tablename add 列名称1 列类型[列参数][not null default]
- alter table tablename change 旧列名 新列名[列参数][not null default]
- alter table tablename drop 列名
- alter table tablename add primary key 列名
- alter table tablename drop primary key 列名
- alter table tablename add unique|fulltext index 索引名
- alter table tablename drop index 索引名
- truncate table
4. 列类型讲解
- tinyint
- smallint
- mediumint
- int
- bigint
- float、double
- char (m) 定长、varchar(m) 变长、text
- text
- year
- date
- time
- datetime
- timestamp (不用赋值,改列会自己赋当前的具体时间)
5. 增删改查基本操作
- insert into 表(col1,col2,…)values(val1,val2,…)
- insert into 表 values(,,,);
- insert into 表
(,,,),
(,,,)
- update 表 set col1=val1,col2=val2,… where 条件;
- delete from 表 where 条件
- 条件查询:

1. 条件表达式的意义,表达式为真,则该行取出
2. 比较运算符=,!=,<><=>=
3. like,not like,in,not,between and
4. is null,is not null

- group by 使用的max、min、sum、avg、count
- having
- order by
- limit
- 连接查询
- 左连接 left join on
- 右连接 right join on
- 内连接 inner join
左右连接都是以在左边的表的数据为准,沿着左表查右表。
内连接是以两张表都有的共同部分数据为准备,也就是左右连接的数据之交集。
7. 子查询
- where型子查询
- from型子查询
8. 字符集

原创粉丝点击