怎么用concat批量生成MySQL查询语句

发布时间:2021-09-27 17:43 来源:亿速云 阅读:0 作者:chen 栏目: Mysql 欢迎投稿:712375056

这篇文章主要介绍“怎么用concat批量生成查询语句”,在日常操作中,相信很多人在怎么用concat批量生成MySQL查询语句问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用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 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' ;

免责声明:本站发布的内容(图片、视频和文字)以原创、来自本网站内容采集于网络互联网转载等其它媒体和分享为主,内容观点不代表本网站立场,如侵犯了原作者的版权,请告知一经查实,将立刻删除涉嫌侵权内容,联系我们QQ:712375056,同时欢迎投稿传递力量。