RBAC权限设计(一)
序言
RBAC表结构
用户表
角色表
权限表
用户角色(关系)表
角色权限(关系)表
sql脚本
/* Navicat MySQL Data Transfer Source Server : 127.0.0.1 Source Server Version : 50635 Source Host : 127.0.0.1:3306 Source Database : test Target Server Type : MYSQL Target Server Version : 50635 File Encoding : 65001 Date: 2019-07-14 16:27:01 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `permission` -- ---------------------------- DROP TABLE IF EXISTS `permission`; CREATE TABLE `permission` ( `id` int(11) NOT NULL AUTO_INCREMENT, `permission` varchar(255) DEFAULT NULL COMMENT '权限名称', `desc` varchar(255) DEFAULT NULL COMMENT '权限描述', PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -- ---------------------------- -- Records of permission -- ---------------------------- INSERT INTO `permission` VALUES ('1', 'add', '增加'); INSERT INTO `permission` VALUES ('2', 'update', '更新'); INSERT INTO `permission` VALUES ('3', 'select', '查看'); INSERT INTO `permission` VALUES ('4', 'delete', '删除'); -- ---------------------------- -- Table structure for `role` -- ---------------------------- DROP TABLE IF EXISTS `role`; CREATE TABLE `role` ( `id` int(11) NOT NULL AUTO_INCREMENT, `role` varchar(255) DEFAULT NULL, `desc` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -- ---------------------------- -- Records of role -- ---------------------------- INSERT INTO `role` VALUES ('1', 'admin', '超级管理员'); INSERT INTO `role` VALUES ('2', 'user', '普通用户'); INSERT INTO `role` VALUES ('3', 'vip_user', 'VIP用户'); -- ---------------------------- -- Table structure for `role_permission` -- ---------------------------- DROP TABLE IF EXISTS `role_permission`; CREATE TABLE `role_permission` ( `id` int(11) NOT NULL AUTO_INCREMENT, `role_id` int(11) DEFAULT NULL, `permission_id` int(255) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED; -- ---------------------------- -- Records of role_permission -- ---------------------------- INSERT INTO `role_permission` VALUES ('1', '1', '1'); INSERT INTO `role_permission` VALUES ('2', '1', '2'); INSERT INTO `role_permission` VALUES ('3', '1', '3'); INSERT INTO `role_permission` VALUES ('4', '1', '4'); INSERT INTO `role_permission` VALUES ('5', '2', '3'); INSERT INTO `role_permission` VALUES ('6', '3', '3'); INSERT INTO `role_permission` VALUES ('7', '3', '2'); INSERT INTO `role_permission` VALUES ('8', '2', '1'); -- ---------------------------- -- Table structure for `user` -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `password` varchar(255) DEFAULT NULL, `username` varchar(255) DEFAULT NULL, `account` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO `user` VALUES ('1', 'root', '超级用户', 'root'); INSERT INTO `user` VALUES ('2', 'user', '普通用户', 'user'); INSERT INTO `user` VALUES ('3', 'vip', 'VIP用户', 'vip'); -- ---------------------------- -- Table structure for `user_role` -- ---------------------------- DROP TABLE IF EXISTS `user_role`; CREATE TABLE `user_role` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `role_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED; -- ---------------------------- -- Records of user_role -- ---------------------------- INSERT INTO `user_role` VALUES ('1', '1', '1'); INSERT INTO `user_role` VALUES ('2', '2', '2'); INSERT INTO `user_role` VALUES ('3', '3', '3');
资料
http://blog.csdn.net/painsonline/article/details/7183629
http://www.noahweb.net/mail/2/Project.htm#biao
http://blog.csdn.net/painsonline/article/details/7183613/
http://www.imooc.com/video/14137