mysql中的enum和set型別

2021-06-22 02:52:14 字數 1211 閱讀 9709

mysql中的enum和set其實都是string型別的而且只能在指定的集合裡取值, 不同的是set可以取多個值,enum只能取乙個 

create table `20121101_t` (  

`id` int(11) not null auto_increment,

`name` varchar(20) not null,

`cl` set('x','w','r') not null,

`c2` enum('f','d') not null,

primary key (`id`)

) engine=innodb

insert into 20121101_t  

values(null,'a.txt','r,w','d');

insert into 20121101_t  

values(null,'b.txt','r,w','f');

比如給b.txt檔案加上執行許可權 

update 20121101_t set cl = cl|1 where id =2
1是因為x許可權出現在了第乙個 

再比如給b.txt檔案去掉寫許可權 

update 20121101_t set cl = cl&~2 where id =2
這時再看 

select * from 20121101_t  

1 a.txt w,r d

2 b.txt x,r f

可以仿照linux下chmod的用法,直接用數字表示許可權 

比如把b.txt變成唯讀 

update 20121101_t set cl = 4 where id = 2

比如要找到所有包含了讀許可權的檔案 

select * from 20121101_t where cl&4  

select * from 20121101_t where find_in_set('r',cl) > 0

enum就相對簡單了,比如把a.txt從資料夾變成檔案 

update 20121101_t set c2 = 'f' where id =1

**:

mysql中的enum和set型別

mysql中的enum和set其實都是string型別的而且只能在指定的集合裡取值,不同的是set可以取多個值,enum只能取乙個 create table 20121101 t id int 11 not null auto increment,name varchar 20 not null,c...

mysql中的enum和set型別

mysql中的enum和set型別 mysql中的enum和set其實都是string型別的而且只能在指定的集合裡取值,不同的是set可以取多個值,enum只能取乙個 sql create table 20121101 t id int 11 not null auto increment,name...

mysql中的set和enum型別的用法和區別

mysql中的set和enum型別的用法和區別 mysql中的enum和set其實都是string型別的而且只能在指定的集合裡取值,不同的是set可以取多個值,enum只能取乙個值。php create table 20121101 t id int 11 not null auto increme...