我有以下查询:
MySQL [Database]> show grants for "user"@"%";
+-----------------------------------------------------------------+
| Grants for user@% |
+-----------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
现在我要做的是更改Grants for user@%
标题,但是以下语句引发错误:
show grants for "user"@"%" AS TEST;
show grants AS TEST for "user"@"%";
select * from (show grants AS Test for "user"@"%") as SUB;
我想以某种方式获得以下结果:
MySQL [Database]> show grants for "user"@"%" AS TEST;
+-----------------------------------------------------------------+
| TEST |
+-----------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
我要更改标题的原因是因为我使用的PHP框架将数据库查询转换为对象,而Grants for user@%
是对象变量/字段,我需要调用它,这很不方便。
答案 0 :(得分:1)
如果您不喜欢SHOW GRANTS的结果标题,则可以将INFORMATION_SCHEMA中表中的信息汇总在一起:
我将保留它作为练习来编写用于执行此操作的SQL查询。