MySQL中RBAC建表

########################## RBAC ################################
DROP TABLE IF EXISTS php34_admin;
CREATE TABLE php34_admin
(
	 id tinyint unsigned not null auto_increment,
	 username varchar(30) not null comment '账号',
	 password char(32) not null comment '密码',
	 is_use tinyint unsigned not null default '1' comment '是否启用1:启用0:禁用',
	 primary key (id)
)engine=MyISAM default charset=utf8 comment'管理员表';
INSERT INTO php34_admin VALUES(1,'root','bafcbdc80e0ca50e92abe420f506456b',1);

DROP TABLE IF  EXISTS php34_privilege;
CREATE TABLE  php34_privilege
(
	id smallint unsigned not null auto_increment,
	pri_name varchar(30) not null comment "权限名称",
	module_name varchar(10) not null comment '模块名称',
	controller_name varchar(10) not null comment '控制器名称',
	action_name varchar(10) not null comment '方法名称',
	parent_id smallint unsigned not null default '0' comment '上级权限的ID,0:代表顶级权限',
	primary key(id)
)engine=MyISAM default charset=utf8 comment '权限表';
DROP TABLE IF  EXISTS php34_role;
CREATE TABLE  php34_role
(
	id smallint unsigned not null auto_increment,
	role_name varchar(30) not null comment "角色名称",
	primary key(id)
)engine=MyISAM default charset=utf8 comment '角色表';

DROP TABLE IF  EXISTS php34_role_privilege;
CREATE TABLE  php34_role_privilege
(
	pri_id smallint unsigned not null comment '权限的ID',
	role_id smallint unsigned not null comment '角色的ID',
	key pri_id(pri_id),
	key role_id(role_id)
)engine=MyISAM default charset=utf8 comment '角色权限表';

DROP TABLE IF  EXISTS php34_admin_role;
CREATE TABLE  php34__admin_role
(
	admin_id tinyint unsigned not null comment '管理员的ID',
	role_id smallint unsigned not null comment  '角色的ID',
	key admin_id(admin_id),
	key role_id(role_id)
)engine=MyISAM default charset=utf8 comment '管理员角色表';


你可能感兴趣的:(mysql)