当我运行这个脚本时
mysql -e "use sentry;
select DISTINCT
concat(
'CREATE ROLE \`',
r.ROLE_NAME,
'\`;')
from
SENTRY_ROLE r
join SENTRY_ROLE_DB_PRIVILEGE_MAP rp on rp.ROLE_ID = r.ROLE_ID
join SENTRY_DB_PRIVILEGE p on p.DB_PRIVILEGE_ID = rp.DB_PRIVILEGE_ID
;" -u mysql_sel -p$Pass
我得到的输出
+---------------------------------------------------------+
| concat(
'CREATE ROLE `',
r.ROLE_NAME,
'`;') |
+---------------------------------------------------------+
| CREATE ROLE `admin_role`; |
我怎样才能得到唯一的输出
+---------------------------------------------------------+
| CREATE ROLE `admin_role`; |
答案1
用于mysql -N
跳过输出 ASCII 表上的列名称。以您的命令行为例:
mysql -N -e "use sentry;
select DISTINCT
concat(
'CREATE ROLE \`',
r.ROLE_NAME,
'\`;')
from
SENTRY_ROLE r
join SENTRY_ROLE_DB_PRIVILEGE_MAP rp on rp.ROLE_ID = r.ROLE_ID
join SENTRY_DB_PRIVILEGE p on p.DB_PRIVILEGE_ID = rp.DB_PRIVILEGE_ID
;" -u mysql_sel -p$Pass