mysql 5.6 5.7 匯出使用者授權資訊
阿新 • • 發佈:2019-01-07
1. 5.6授權資訊
我做了一點點改動實測可用;
#!/bin/bash
#Function export user privileges
# updated by tsong
source /etc/profile
pwd=password
expgrants()
{
mysql -B -u'root' -p${pwd} -N -P3306 [email protected] -e "SELECT CONCAT( 'SHOW GRANTS FOR ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \
mysql -u'root' -p${pwd} -P3306 -f [email protected] | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/-- \1 /;/--/{x;p;x;}'
}
expgrants > ./grants.sql
2. 5.7授權資訊:
mysql 5.7暫時發現這兩個點變動:
1. mysql.user 儲存加密密碼欄位的變動
2.show grants for ; 不會出現 identified by 資訊;需要使用 show create user ;
這樣子上面5.6的指令碼就使用不了,修改為下面指令碼,實測可用(但是沒有更具體驗證~~):
#/bin/bash
#updated by tsong
#Function export user privileges
#5.7存在問題: show grants for 不會給出密碼資訊,必須用 show create user
# https://dev.mysql.com/doc/refman/5.7/en/show-grants.html
# show create user 為5.7版本開始存在,5.6執行報錯。
source /etc/profile
pwd=password
expgrants()
{
mysql -B -u'root' -p${pwd} -N -P3306 [email protected] -e "SELECT CONCAT( 'SHOW CREATE USER ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \
mysql -u'root' -p${pwd} -P3306 -f [email protected] | \
sed 's#$#;#g;s/^\(CREATE USER for .*\)/-- \1 /;/--/{x;p;x;}'
mysql -B -u'root' -p${pwd} -N -P3306 [email protected] -e "SELECT CONCAT( 'SHOW GRANTS FOR ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \
mysql -u'root' -p${pwd} -P3306 -f [email protected] | \
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/-- \1 /;/--/{x;p;x;}'
}
expgrants > ./5.7_grants.sql