【MySQL】MySQL导出用户权限信息
2022-09-20 14:00 abce 阅读(328) 评论(0) 编辑 收藏 举报$ vim MyDatabaseUSers.sql
#!/bin/bash GRANT_CMDS=/tmp/ShowGrantsToExport.sql GRANT_FILE=MyDatabaseUSers.sql MYSQL_USER=root MYSQL_PASS=root MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}" SQL="SELECT CONCAT('SHOW GRANTS FOR ',QUOTE(user),'@',QUOTE(host),';')" SQL="${SQL} FROM mysql.user WHERE user<>'' AND host<>''" mysql ${MYSQL_CONN} -ANe"${SQL}" > ${GRANT_CMDS} mysql ${MYSQL_CONN} < ${GRANT_CMDS} | sed 's/$/;/g' > ${GRANT_FILE}