批量獲取mysql使用者許可權的方法
阿新 • • 發佈:2018-11-06
-- 伺服器級別的許可權
select a.GRANTEE,GROUP_CONCAT(a.PRIVILEGE_TYPE), concat("grant ",GROUP_CONCAT(a.PRIVILEGE_TYPE)," ON *.* to " ,a.GRANTEE ) from USER_PRIVILEGES a GROUP BY GRANTEE ;
-- db 級別的許可權
select GRANTEE,TABLE_SCHEMA,GROUP_CONCAT(PRIVILEGE_TYPE), concat("grant ",GROUP_CONCAT(PRIVILEGE_TYPE)," ON ",TABLE_SCHEMA,".* to " ,GRANTEE ) from information_schema.SCHEMA_PRIVILEGES GROUP BY GRANTEE,TABLE_SCHEMA ;
-- 表級別的許可權
select GRANTEE,TABLE_SCHEMA,table_name,GROUP_CONCAT(PRIVILEGE_TYPE), concat("grant ",GROUP_CONCAT(PRIVILEGE_TYPE)," ON ",TABLE_SCHEMA,".",table_name," to " ,GRANTEE ) from information_schema.TABLE_PRIVILEGES GROUP BY GRANTEE,TABLE_SCHEMA,table_name ;
-- 列級別許可權
select GRANTEE,TABLE_SCHEMA,table_name,COLUMN_NAME,GROUP_CONCAT(PRIVILEGE_TYPE) from information_schema.COLUMN_PRIVILEGES GROUP BY GRANTEE,TABLE_SCHEMA,table_name,COLUMN_NAME ;
-- 獲取使用者許可權和密碼(密文)
select a.GRANTEE,GROUP_CONCAT(a.PRIVILEGE_TYPE), concat("grant ",GROUP_CONCAT(a.PRIVILEGE_TYPE)," ON *.* to " ,a.GRANTEE ," identified by password '",c.authentication_string,"';" ) privi from USER_PRIVILEGES a left join mysql.user c on a.GRANTEE = concat("'",c.user,"'","@","'",c.host,"'") GROUP BY GRANTEE ;