需求背景:
一個庫有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' ;