SQL:数据库授权

莫忘

授权后及时刷新:flush privileges;

创建用户

设置密码:
insert into mysql.user(Host,User,Password) values("xx.xx.38.xx","rrw_reader",password("xxxxxx"));
更新密码:
update mysql.user set password=password(‘新密码’) where User="reader" and Host="";
某些时候需要放开更大权限,比如写存储过程等:
update user set Super_priv='Y' where User='xx'
update mysql.user SET Grant_priv ='Y', Super_priv='Y' WHERE User='xx';

普通数据用户通用增删改查

单独授权:
grant select on testdb.* to common_user@'%';
grant insert on testdb.* to common_user@'%';
grant update on testdb.* to common_user@'%';
grant delete on testdb.* to common_user@'%';
grant execute on testdb.* to common_user@'%';
联合授权:
grant select, insert, update, delete on testdb.* to common_user@'%'
grant all privileges on testdb.* to common_user@localhost identified by 'testdb';
flush privileges;

读授权

grant select on test_db_name.test_table_name to rrw_reader@'xxx.xxx.38.242'; 
flush privileges;

插入更新授权

grant insert on testdb.* to common_user@'%';
grant update on testdb.* to common_user@'%';
flush privileges;

删除授权

grant delete on testdb.* to common_user@'%';
flush privileges;

例程授权

grant create routine on bi2_cache.* to xxx@'xx.xx.38.242'; 
grant alter routine on bi2_cache.* to xxx@'xx.xx.38.242';

查看例程

show procedure status;
SHOW CREATE PROCEDURE mapping_interval_and_date_type\G

posted @ 2019-12-11 16:55  Adamanter  阅读(593)  评论(0编辑  收藏  举报