备份MySQL用户[英] Backup MySQL users

本文是小编为大家收集整理的关于备份MySQL用户的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何备份MySQL用户及其特权?

类似mysqldump的东西?

我正在寻找:

mysqldump -d -u root -p MyTable > Schema.sql

推荐答案

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

其他推荐答案

您可以使用

备份MySQL数据库
mysqldump -u root -p mysql > mysql.sql

和通过执行

来还原mySQL数据库
 mysql -uroot -p mysql < mysql.sql

不要忘记

FLUSH PRIVILEGES

恢复转储后.

希望它有帮助...

其他推荐答案

到目前为止,我在MySQL上的经验,我没有看到备份用户及其特权通过命令行.

但是我可以通过备份mySQL

来备份这些关键数据
mysqldump -u root -p mysql > mysql.sql

本文地址:https://www.itbaoku.cn/post/597485.html

问题描述

How do I backup MySQL users and their privileges?

Anything like mysqldump?

I am looking for something like:

mysqldump -d -u root -p MyTable > Schema.sql

推荐答案

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

其他推荐答案

You can backup mysql database using

mysqldump -u root -p mysql > mysql.sql

and restore mysql database by executing

 mysql -uroot -p mysql < mysql.sql

Dont forget to

FLUSH PRIVILEGES

after restoring dump.

Hope it helps...

其他推荐答案

So far my experience with MySQL i didn't see anything to backup user and their privileges through a command line.

But i can backup those critical data by backing up mysql

mysqldump -u root -p mysql > mysql.sql