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