How to Export & Import Existing User (with its Privileges!)

后端 未结 9 2144
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 17:01

I have an existing MySQL instance (test), containing 2 databases and a few users each having different access privileges to each database.

I now need to duplicate one of

9条回答
  •  一个人的身影
    2021-02-03 17:34

    In complement of @Sergey-Podushkin 's answer, this shell script code is workin for me:

    mysql -u -p -N mysql -e "select concat(\"'\", user, \"'@'\", host, \"'\"), authentication_string from user where not user like 'root'" | while read usr pw ; do mysql -u -p -N -e "SHOW GRANTS FOR $usr" | sed 's/\(\S\)$/\1;/'; done 
    

提交回复
热议问题