需求背景:
一个库有2个用户,好比gsgz和gxsnerp。
gsgz的用户有这个库的全部权限,而gxsnerp这个用户只有部分表的权限,因此不能直接用grant all on ...这个语句来给权限,稍微快一点的方法就是批量生成拼接的SQL语句。ide
select concat('grant all on ', table_schema,".",table_name," to ' gxsnerp'@'localhost ';") from tables where table_schema='gxsnerp' and table_name like 'ACT%';
生成拼接语句以下:code
grant all on gxsnerp.ACT_HI_VARINST` to 'gxsnerp'@'localhost'; grant all on gxsnerp.ACT_GE_PROPERTY to 'gxsnerp'@'localhost'; grant all on gxsnerp.ACT_ID_MEMBERSHIP to 'gxsnerp'@'localhost' ; grant all on gxsnerp.ACT_HI_ACTINST to 'gxsnerp'@'localhost' ;