mysql許可權使用者設定

2021-08-14 08:37:12 字數 2446 閱讀 7103

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';

Mysql 使用者許可權設定

關於mysql的使用者管理,筆記 1 建立新使用者 通過root使用者登入之後建立 grant all privileges on to testuser localhost identified by 123456 建立新使用者,使用者名為testuser,密碼為123456 grant all ...

mysql使用者許可權設定

1 建立新使用者 通過root使用者登入之後建立 grant all privileges on to testuser localhost identified by 123456 建立新使用者,使用者名為testuser,密碼為123456 grant all privileges on to ...

mysql使用者許可權設定

關於mysql的使用者管理,筆記 1 建立新使用者 通過root使用者登入之後建立 grant all privileges on to testuser localhost identified by 123456 建立新使用者,使用者名為testuser,密碼為123456 grant all ...