Mysql数据库

1 安装配置
博客

2 找mysql所有配置
show variables like '%';

3 mysql种查看用户的信息
use mysql
select User,Host,authentication_string from user;

4 修改密码
set password for root@localhost = password('123');

5 完整连接指令
mysql -h 106.52.150.96 -p 3306 -u alex -p 123

create user 'alex'@'%' identified by '123'; 创建用户
grant all privileges on db.* to 'alex'@'%'; 给权限

revoke all privileges from user db.* to 'alex'@'%'; 删除权限

6 数据库常用操作
创建库:create database 数据库名;
选择库:use 数据库名;
查看库:show databases;
删除库:drop database 数据库名;

7 查看当前登录用户
select user();

8 数据表常用操作
创建表:create table 表名(id primay auth_increment int);
查看表:show tables;
查看表结构: desc 表名;

9 存储引擎
innodb myisam
innodb支持事物 行级锁
myisam 表锁
区别:
1 innodb存储引擎数据跟索引文件放在一个文件中,myisam分为不同的文件
2 innodb支持事物,myisam不支持
3 innodb支持表锁和行锁,myisam只支持表锁
4 innodb有外键,myisam没有外键

10 数据类型
数值类型 int bigint tinyint unsigned 无符号,不能为负数
字符串类型 char(定长)效率高 255字节最高 varchar(变长) 65535字节最高
时间类型 date time datetime
枚举类型 enum('man','faleman')


11 完整性约束
not null 不能为空
default 指定默认值
auth_increment 自增
primay key 主键 == unique + not null
unique 唯一,不能重复(加速查找)
foreign key 外键 t1_id int, constraint t2_t1_fk foreign key(t1_id) references t2_id;


12 数据基本操作
增 insert into t1('name') values('jack');
删 delete from t1 where id=1;
改 update t1 set name='alex' where id=1;
查 select * from t1;

13 查询条件
where 条件 < > = != in like and or not between and
group by 字段 分组 max min count avg sum
having 筛选 和分组用
order by 字段 排序 asc desc
limit 0,1 分页
关键字的优先级:
1 from
2 where
3 group by
4 having
5 select
6 distinct
7 order by
8 limit 0,1;

14 连表方式
inner join on 内连接
left join on 左连接
right join on 右连接

15 视图
create view 视图名 as sql语句
drop view 名;

16 触发器 自动调用
pass

17 事物
要么都执行,要么都不执行
开启事物: begin;
结束事物: commit;

18 存储过程
pass

19 索引
主键索引 id int primay key auth_increment
唯一索引 id int unique
联合索引 index index_name(id,name)

20 如何命中索引
联合索引遵循最左前缀原则
索引不使用函数
or多个条件必须每个字段都是索引字段
通配符使用的时候,%_不能在第一个
order by > 等 除了主键外 其他都不命中索引

21 面试题
索引分类
索引是放在磁盘当中,是为了持久化存储
普通索引
主键
唯一索引
联合索引
innodb的底层数据结构

为什么底层使用B+树而不是用B树

 

posted @ 2020-08-17 13:12  李淳罡zZ  阅读(91)  评论(0)    收藏  举报