Mysql学习回顾整理

mysql锁:最常用的是表级锁、行级锁、库级索、事务锁
底层存储结构:bTree
100个数值:二叉树而言,最好的情况

Mysql:数据库管理系统(dbms)
库:存储数据的地方
表:定义一种关系,用于数据与关系的对应
视图:可以看作是一个虚拟表,表结构和数据由定义的查询语句决定
作用:提高代码重用性,安全,对外接口统一
劣势:效率低下,在连表的基础上不能进行增删改
触发器:增删改操作的条件触发
作用:自动执行某些操作,减少流程
劣势:定义时不校验触发语句的有效性
insert:new
delete:old
update:new、old
存储过程:相当于void方法,但是可以有出参,注重的是过程
函数:相当于有返回值的方法,注重的是返回值
索引:主键primary key:不重复、查询检索速度快
唯一索引unique:基本同主键,但是可以有多个
普通索引index:提高查询效率
全文索引:提高查询效率,只能在MyISAM引擎的表中使用
语句的分类:
DDL:对库和表本身的操作:create、drop、alter
DML:对数据的增删改:insert、delete、update
DQL:对数据的查询:select
DCL:赋权和事务支持:grant、commit、rollback
库的操作:
create database [if not exists] 库名;
drop database [if exists] 库名;
show databases;
grant select on 库名.表名 to ‘用户名’ @ ‘ip地址’ identified by '密码;
表的操作:
create table [if not exists] 表名(
字段名 类型(长度) [属性 索引] [注释],

);
drop table [if exists] 表名;
alter table 表名 rename to 新表名;
alter table 表名 add column 字段名 类型(长度) [属性 索引] [注释];
show tables;
desc 表名;
show create table 表名;
数据操作:
update 表名 set 列名=值 [,…] where 条件;
delete from 表名 where 条件;
truncate [table] 表名;
insert into 表名 [(字段列表)] values(对应的值列表) [,…];
select [distinct] { *|字段列表 } from 表名 [xxx join 表名 on ]
[where 条件]
[group by 分组字段]
[order by 分组条件]
[having 排序字段 ]
[limit a,b];
事务:略
备份:
mysqldump [-h主机名] -u用户名 -p [options] 库名 [表名列表] > 文件路径 ;
恢复 : mysql [-h主机名] -u用户名 -p 库名 < 文件路径;
在命令行:source 文件路径;
改变结束符:
delimiter//
delimiter;
取消自动提交;
set autocommit=0;
恢复自动提交
set autocommit=1;

数据库设计:吃货联盟
商家 tb_shop
shop_id | shop_name | shop_type | shop_address | shop_phone | work_time
商家评价表 tb_shop_comment
comment_id | shop_id | comment_person | comment_detail | comment_time | level
菜品 tb_dish
dish_id | dish_name | shop_id | price | dish_type | dish_detail
| saled_num
菜品分类(字典表) tb_dish_type
type_id | type_name
菜品评价表 tb_dish_comment
comment_id | dish_id | comment_person |comment_detail | comment_time | level
用户 tb_dish
user_id | user_name | phone | address | gender | birthday | pay_type 支付类型表(字典表) tb_pay
pay_type_id | pay_type_name | support_brand
用户VIP等级(字典表)
vip_id | user_id | charge_percent | vip_name | affect_time | deffect_time
订单(增量表)
bill_id | bill_name | user_id | dish_id | dish_num | total_price | send_person | start_time | end_time | finish_time | expire_time | status |
bill_detail
订单历史
bill_id | bill_name | user_id | dish_id | dish_num | total_price | send_person | start_time | end_time | finish_time | expire_time | status |
bill_detail

配送
配送员
send_person_id | send_person_name | phone | gender
配送历史
send_history_id | send_person_id | bill_id | isSuccess | send_time |
send_distance |
配送评价
send_comment_id | comment_person | comment_detail | comment

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值