mysql 5 6 5 7 匯出使用者授權資訊

2021-08-14 16:05:01 字數 1507 閱讀 1117

參考:

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

#!/bin/bash  

#function export user privileges

# updated by tsong

source /etc/profile

pwd=password

expgrants()

-n -p3306 $@ -e "select concat( 'show grants for ''', user, '''@''', host, ''';' ) as query from mysql.user" | \

mysql -u'root' -p$ -p3306 -f $@ | \

sed 's/\(grant .*\)/\1;/;s/^\(grants for .*\)/-- \1 /;/--/'

} expgrants > ./grants.sql

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

#

# show create user 為5.7版本開始存在,5.6執行報錯。

source /etc/profile

pwd=password

expgrants()

-n -p3306 $@ -e "select concat( 'show create user ''', user, '''@''', host, ''';' ) as query from mysql.user" | \

mysql -u'root' -p$ -p3306 -f $@ | \

sed 's#$#;#g;s/^\(create user for .*\)/-- \1 /;/--/'

mysql -b -u'root' -p$ -n -p3306 $@ -e "select concat( 'show grants for ''', user, '''@''', host, ''';' ) as query from mysql.user" | \

mysql -u'root' -p$ -p3306 -f $@ | \

sed 's/\(grant .*\)/\1;/;s/^\(grants for .*\)/-- \1 /;/--/'

} expgrants > ./5.7_grants.sql

mysql 授權 mysql 使用者授權

mysql grant 許可權1,許可權2,許可權n on 資料庫名稱.表名稱 to 使用者名稱 使用者位址 identified by 連線口令 許可權1,許可權2,許可權n代表select,insert,update,delete,create,drop,index,alter,grant,re...

mysql授權使用者許可權 mysql授權使用者許可權

grant 普通資料使用者,查詢 插入 更新 刪除 資料庫中所有表資料的權利。grant select on testdb.to common user grant insert on testdb.to common user grant update on testdb.to common us...

mysql授權 MySQL使用者授權(GRANT)

當成功建立使用者賬戶後,還不能執行任何操作,需要為該使用者分配適當的訪問許可權。可以使用 show grant for 語句來查詢使用者的許可權。注意 新建立的使用者只有登入 mysql 伺服器的許可權,沒有任何其他許可權,不能進行其他操作。usage on 表示該使用者對任何資料庫和任何表都沒有許...