mysql 5.6 5.7 導出用戶授權信息

1.  5.6授權信息 

參考:http://blog.csdn.net/yumushui/article/details/50264123

我做了一點點改動實測可用;

#!/bin/bash  
#Function export user privileges  
# updated by tsong
source /etc/profile

pwd=password 
expgrants()  
{  
  mysql -B -u'root' -p${pwd} -N  -P3306  $@ -e "SELECT CONCAT(  'SHOW GRANTS FOR ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \
  mysql -u'root' -p${pwd} -P3306 -f  $@ | \
  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 ;

參考: https://dev.mysql.com/doc/refman/5.7/en/show-grants.html

這樣子上面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  $@ -e "SELECT CONCAT(  'SHOW CREATE USER   ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \
  mysql -u'root' -p${pwd} -P3306 -f  $@ | \
  sed 's#$#;#g;s/^\(CREATE USER for .*\)/-- \1 /;/--/{x;p;x;}' 
 
  mysql -B -u'root' -p${pwd} -N  -P3306  $@ -e "SELECT CONCAT(  'SHOW GRANTS FOR ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \
  mysql -u'root' -p${pwd} -P3306 -f  $@ | \
  sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/-- \1 /;/--/{x;p;x;}'   
}  

expgrants > ./5.7_grants.sql

參考:

http://blog.csdn.net/yumushui/article/details/50264123

https://dev.mysql.com/doc/refman/5.7/en/show-grants.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章