mysql中逻辑备份mysqldump的使用

前言

mysqldump是进行mysql逻辑备份的命令工具

使用

常用备份命令

mysqldump -h <DB_ADDRESS> -P <DB_PORT> -u <DB_USER> -p <DB_PASSWORD> [--single-transaction] --default-character-set=utf8mb4  [--opt] --comments --databases/--all-databases <DB_NAME> 2> /dev/null | gzip <BACKUP_FILE>
  • 补充
    数据库还原
gunzip -c <BACKUP_FILE> | mysqldump -h <DB_ADDRESS> -P <DB_PORT> -u <DB_USER> -p <DB_PASSWORD> <DB_NAME>

命令参数解析

  • –single-transaction
    Issue a BEGIN SQL statement before dumping data from server/在从服务器转储数据之前发出BEGIN SQL语句
    作用:保证数据一致性,仅对 InnoDB 存储引擎有效,还需要保证没有其他的连接正在使用以下语句: ALTER TABLE, CREATE TABLE,DROP TABLE, RENAME TABLE, TRUNCATE TABLE;与–lock-tables 选项是互斥的,因为LOCK TABLES 会使任何挂起的事务隐含提交。要想导出大表的话,应结合使用–quick 选项

  • –default-character-set
    指定默认字符集

  • –opt
    Shorthand for --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset

--add-drop-table:Add DROP TABLE statement before each CREATE TABLE statement/在每个 CREATE TABLE 语句之前添加 DROP TABLE 语句
--add-locks:Surround each table dump with LOCK TABLES and UNLOCK TABLES statements/用 LOCK TABLES 和 UNLOCK TABLES 语句包围每个表转储
--create-options:Include all MySQL-specific table options in CREATE TABLE statements/在 CREATE TABLE 语句中包含所有 MySQL 特定的表选项
--disable-keys:For each table, surround INSERT statements with statements to disable and enable keys/对于每个表,用禁用和启用键的语句包围 INSERT 语句
--extended-insert:Use multiple-row INSERT syntax/使用多行 INSERT 语法
--lock-tables:Lock all tables before dumping them/在转储之前锁定所有表
--quick:Retrieve rows for a table from the server a row at a time/一次一行地从服务器检索表的行
--set-charset:	Add SET NAMES default_character_set to output/将 SET NAMES default_character_set 添加到输出

  • –comments
    Add comments to dump file/向转储文件添加注释
结语

mysqldump 官方介绍
使用mysqldump迁移MySQL数据
MySQL mysqldump数据导出详解

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值