Backup MySQL users

后端 未结 8 2016
无人及你
无人及你 2021-01-31 09:15

How do I backup MySQL users and their privileges?

Anything like mysqldump?

I am looking for something like:

mysqldump -d -u root -p MyTable &         


        
8条回答
  •  不思量自难忘°
    2021-01-31 09:15

    probably pretty obvious for mysql command liners but for spirit's answer above had to add -u root -ppassword after both mysql commands

    mysql -u root -ppassword -BNe "select concat('\'',user,'\'@\'',host,'\'') from mysql.user where user != 'root'" | while read uh; do mysql -u root -ppassword -BNe "show grants for $uh" | sed 's/$/;/; s/\\/\/g'; done > grants.sql;

提交回复
热议问题