mysql全库备份用户_如何用所有用户以及权限和密码备份整个MySQL数据库?

bd96500e110b49cbb3cd949968f18be7.png

I need to backup the whole of a MySQL database with the information about all users and their permissions and passwords.

I see the options on http://www.igvita.com/2007/10/10/hands-on-mysql-backup-migration/,

but what should be the options to backup all of the MySQL database with all users and passwords and permissions and all database data?

Just a full backup of MySQL so I can import later on another machine.

解决方案

At it's most basic, the mysqldump command you can use is:

mysqldump -u$user -p$pass -S $socket --all-databases > db_backup.sql

That will include the mysql database, which will have all the users/privs tables.

There are drawbacks to running this on a production system as it can cause locking. If your tables are small enough, it may not have a significant impact. You will want to test it first.

However, if you are running a pure InnoDB environment, you can use the --single-transaction flag which will create the dump in a single transaction (get it) thus preventing locking on the database. Note, there are corner cases where the initial FLUSH TABLES command run by the dump can lock the tables. If that is the case, kill the dump and restart it. I would also recommend that if you are using this for backup purposes, use the --master-data flag as well to get the binary log coordinates from where the dump was taken. That way, if you need to restore, you can import the dump file and then use the mysqlbinlog command to replay the binary log files from the position where this dump was taken.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值