harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

DB MySQL

[MySQL]mysqlのGRANT情報を抜粋するシェルスクリプト

投稿日:2014年5月29日

 
ただの道具。
DBサーバーの現状調査用に。

mysql_grant_export.sh

#!/bin/bash

    mysql -uroot -p<パスワードを入れる> -e "select user,host from mysql.user" | sed -e 's/\t/\ @/g' > mysql.user.txt

    touch grant_export.txt

while read LINE
    do
        mysql -uroot -p<パスワードを入れる> -e "SHOW GRANTS FOR ${LINE}" >> grant_ export.txt
    done < mysql.user.txt

    #rm -f mysql.user.txt
exit 0

mysql.user.txt 出力例

※一番上の”user@host”は行頭の項目なので無視で。または削除する。

user@host
root@127.0.0.1
repl@172.16.128.0/255.255.255.0
productuser@172.16.128.11
productuser@172.16.128.12
productuser@172.16.128.4
devuser@172.16.128.4
dump_user@172.16.128.8
productuser@172.16.128.8
devuser@172.16.128.8
root@::1
root@ip-172-16-128-11
@localhost
productuser@localhost
devuser@localhost
root@localhost

grant_export.txt 出力例

Grants for root@127.0.0.1
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION
Grants for productuser@172.16.128.11
GRANT USAGE ON *.* TO 'productuser'@'172.16.128.11' IDENTIFIED BY PASSWORD '***************'
GRANT SELECT, INSERT, UPDATE, DELETE ON `productuseruction`.* TO 'productuser'@'172.16.128.11'
Grants for productuser@172.16.128.12
GRANT USAGE ON *.* TO 'productuser'@'172.16.128.12' IDENTIFIED BY PASSWORD '***************'
GRANT SELECT, INSERT, UPDATE, DELETE ON `productuseruction`.* TO 'productuser'@'172.16.128.12'
Grants for productuser@172.16.128.4
GRANT USAGE ON *.* TO 'productuser'@'172.16.128.4' IDENTIFIED BY PASSWORD '***************'
GRANT SELECT, INSERT, UPDATE, DELETE ON `productuseruction`.* TO 'productuser'@'172.16.128.4'
Grants for devuser@172.16.128.4
GRANT USAGE ON *.* TO 'devuser'@'172.16.128.4' IDENTIFIED BY PASSWORD '***************'
GRANT SELECT, INSERT, UPDATE, DELETE ON `pjt_development`.* TO 'devuser'@'172.16.128.4'
Grants for dump_user@172.16.128.8
GRANT SELECT, RELOAD, FILE, LOCK TABLES, SHOW VIEW ON *.* TO 'dump_user'@'172.16.128.8' IDENTIFIED BY PASSWORD '***************'
Grants for productuser@172.16.128.8
GRANT USAGE ON *.* TO 'productuser'@'172.16.128.8' IDENTIFIED BY PASSWORD '***************'
GRANT SELECT, INSERT, UPDATE, DELETE ON `productuseruction`.* TO 'productuser'@'172.16.128.8'
Grants for devuser@172.16.128.8
GRANT USAGE ON *.* TO 'devuser'@'172.16.128.8' IDENTIFIED BY PASSWORD '***************'
GRANT SELECT, INSERT, UPDATE, DELETE ON `pjt_development`.* TO 'devuser'@'172.16.128.8'
Grants for productuser@localhost
GRANT USAGE ON *.* TO 'productuser'@'localhost' IDENTIFIED BY PASSWORD '***************'
GRANT ALL PRIVILEGES ON `productuseruction`.* TO 'productuser'@'localhost'
Grants for devuser@localhost
GRANT USAGE ON *.* TO 'devuser'@'localhost' IDENTIFIED BY PASSWORD '***************'
GRANT ALL PRIVILEGES ON `pjt_development`.* TO 'devuser'@'localhost'
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '***************' WITH GRANT OPTION
GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

 

-DB, MySQL
-,

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA


関連記事