mysql权限用户设置
2018-01-05 08:37
183 查看
Drop user 'employA'@'localhost';删除一个用户
新建三个用户
CREATE USER 'employeeA'@'localhost' IDENTIFIED BY '1234';
CREATE USER 'employeeB'@'localhost' IDENTIFIED BY '1234';
CREATE USER 'employerM'@'localhost' IDENTIFIED BY '1234';
新建四张表
CREATE TABLE IF NOT EXISTS t1(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS t2(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS t3(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS t4(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
use mysql;
由数据库管理员将表t1,t2所有权限给雇员A
grant all privileges on mysql.t1 to employeeA@localhost identified by '1234';
grant all privileges on mysql.t2 to employeeA@localhost identified by '1234';
由数据库管理员将表t3,t4所有权限给雇员B
grant all privileges on mysql.t3 to employeeB@localhost identified by '1234';
grant all privileges on mysql.t4 to employeeB@localhost identified by '1234';
回收权限
REVOKE all privileges on mysql.t2 FROM 'employeeA'@'localhost';(也可以回收WITH GRANT OPTION,只是在查看时还是会显示)
查看用户所拥有的权限
show grants for 'employeeA'@'localhost';
show grants for 'employeeB'@'localhost';
show grants for 'employerM'@'localhost';
审计功能
create database audit;
CREATE TABLE audit.check (id int(11) primary key auto_increment, time timestamp, localname varchar(30), matchname varchar(30));
set global init_connect='insert into audit.check values(connection_id(),now(),user(),current_user())';
flush privileges;
给予数据库管理员读审计内容
grant select on audit.* to root;
给予角色insert
grant insert on audit.* to 'employeeA'@'localhost';
grant insert on audit.* to 'employeeB'@'localhost';
grant insert on audit.* to 'employerM'@'localhost';
新建三个用户
CREATE USER 'employeeA'@'localhost' IDENTIFIED BY '1234';
CREATE USER 'employeeB'@'localhost' IDENTIFIED BY '1234';
CREATE USER 'employerM'@'localhost' IDENTIFIED BY '1234';
新建四张表
CREATE TABLE IF NOT EXISTS t1(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS t2(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS t3(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS t4(
id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
cate VARCHAR(40) NOT NULL,
price DECIMAL(15,3) UNSIGNED NOT NULL DEFAULT 0
);
use mysql;
由数据库管理员将表t1,t2所有权限给雇员A
grant all privileges on mysql.t1 to employeeA@localhost identified by '1234';
grant all privileges on mysql.t2 to employeeA@localhost identified by '1234';
由数据库管理员将表t3,t4所有权限给雇员B
grant all privileges on mysql.t3 to employeeB@localhost identified by '1234';
grant all privileges on mysql.t4 to employeeB@localhost identified by '1234';
回收权限
REVOKE all privileges on mysql.t2 FROM 'employeeA'@'localhost';(也可以回收WITH GRANT OPTION,只是在查看时还是会显示)
查看用户所拥有的权限
show grants for 'employeeA'@'localhost';
show grants for 'employeeB'@'localhost';
show grants for 'employerM'@'localhost';
审计功能
create database audit;
CREATE TABLE audit.check (id int(11) primary key auto_increment, time timestamp, localname varchar(30), matchname varchar(30));
set global init_connect='insert into audit.check values(connection_id(),now(),user(),current_user())';
flush privileges;
给予数据库管理员读审计内容
grant select on audit.* to root;
给予角色insert
grant insert on audit.* to 'employeeA'@'localhost';
grant insert on audit.* to 'employeeB'@'localhost';
grant insert on audit.* to 'employerM'@'localhost';
相关文章推荐
- mysql 用户管理和权限设置
- mysql 用户管理和权限设置
- MySQL中导出用户权限设置的脚本分享
- MySQL中导出用户权限设置的脚本分享
- [置顶] mysql设置用户权限
- [置顶] mysql设置用户权限
- mysql用户权限设置
- Mysql用户密码设置修改和权限分配
- Mysql 远程登陆用户权限设置
- Mysql用户密码设置修改和权限分配
- mysql用命令创建用户创建数据库设置权限
- mysql中为用户设置数据库,数据表,字段(列)的访问权限
- mysql 用户管理和权限设置
- [置顶] mysql设置用户权限
- [置顶] mysql设置用户权限
- 异机远程连接mysql时user表内的用户权限设置
- Mysql 用户权限设置
- mysql 用户管理和权限设置和Mysql初始化root密码和允许远程访问
- mysql 用户管理和权限设置
- MYSQL新建用户并设置权限