不同的是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