1. 程式人生 > 其它 >(十九)、SpringCloud Alibaba Sentinel實現熔斷和限流

(十九)、SpringCloud Alibaba Sentinel實現熔斷和限流

許可權管理

略(公司一般會有專門負責資料庫許可權的管理人員 開發人員可以暫時不去了解 用到時檢視下文件)

常用語法(8.0之後略有不同)

操作資料庫以及資料表

create database db_test default charset utf8;
show databases;
drop database db_test;
show tables;

create table t1(
    列名,型別,是否為空(null/not null),預設值(default 10),auto_increment,primary key 
    id int(11),
    name char(10) 
) engine=innodb default charset=utf8;

drop table t1;

表操作之增刪改查

insert into t1(id,name) values(1,'schlafen');
select * from t1;
delete from t1;
update t1 set age =999 where name = 'schlafen';
truncate table t1;

資料型別

  • 數字
    int(ubsigned int 無符號)
    tinyint
    bigint

FLOAT
DOUBLE
decimal(精準儲存 底層字串)

  • 字串
    char(位數嚴格 多出來的自動填充 速度快)
    varchar(節省空間)
    text

  • 時間型別
    DATETIME

資料庫基礎

主鍵

primary key
一張表只有1個主鍵,一個主鍵可以是多列
create table t1(
nid int(11),
pid int(11),
primary key(nid,pid)
) engine=innodb default charset=utf8;

唯一索引

約束不能重複(可以為空,區別於主鍵的不能為空)
加速查詢
create table t1(
id int(11),
num int(11),
xx int(11),
//unique uql(num)
//unique uql(num,xx) 聯合唯一索引
) engine=innodb default charset=utf8;

外來鍵

外來鍵名字不能重複 外來鍵的列必須為原表主鍵
t1表k1 外來鍵約束 t2表k2
constraint fk_k1_k2 foreign key("k1",) references t2('k2')
多列主鍵時-->
constraint fk_k1_k2 foreign key(id1,id2) references t2(nid,pid)

===》一對多
===》一對一(外來鍵+唯一索引)
===》多對多

SQL語句補充

1.單條插入
2.多條插入 values(x,x,x),(xx,xx,xx)
3.select插入 insert into t1 select id,name from t2

1.別名:select id ,name as cname from t1
2.條件
not in (1,11,111)
between 1 and 10

3.萬用字元
like 'a%' like 'sch_'

4.顯示
limit 10 取10條
limit 1,10 從第1條開始 取一共10條
limit 10 offset 20 從第20條開始 取一共10條

5.排序

6.分組+聚合函式
count max min sum avg
group by
對聚合函式二次篩選時 不能使用where 使用having!!!

7.連表操作
select * from t1,t2 where t1.nid = t2.pid //笛卡爾積做where
select * from t1 left join t2 on t1.nid = t2.pid//推薦

8.臨時表
select ... from (select ...) as B