Using mysqldump for backups

本文围绕使用mysqldump进行MySQL备份展开,介绍了以SQL格式转储数据、重新加载SQL格式备份的方法,还给出了mysqldump的使用技巧,如复制数据库、在服务器间复制数据库、转储存储程序等,以及测试升级或降级兼容性的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

7.4 Using mysqldump for backups

mysql 官网
感觉这个脚本有点厉害
还有这个逼的博客
a dump file used in several ways

  • enable data recovery in case of data loss
  • data for setting up replicas
  • data for experimentations:
    • use without changing the original data
    • to test potential upgrade incompatibilities
7.4.1 dumping data in sql format whith mysqldump
mysqldump [arguments] > file_name

mysqldump --all-databases > dump.sql

mysqldump --databases db1 db2 db3 > dump.sql

–all-databases and --databases write create database and use statements
–add-drop-database write drop database statement

mysqldump test t1 t3 t7 > dump.sql

dump only specific tables from a database

any set @@global.gtid_purged statement in the second dump file fails.
to avoid this issue, either set option --set-gtid-purged to off
or ccommented to output the second dump file whithout an active set @@global.gtid_purged statement,
or remove the statement manually before replaying the dump file

7.4.2 reloading sql-format bakups
mysql < dump.sql

or enter mysql

mysql shell > source dump.sql
7.4.5 mysqldump tips

中间有2小节我不想看,我不想用这个技术

7.4.5.1 making a copy of a database
mysqldump db1 > dump.sql

mysqladmin create db2

mysql db2 < dump.sql

不要使用 --databases sql 脚本会有 use statement

7.4.5.2 copy a database from one server to Another

记得切换 ip

7.4.5.3 dumping stored programs

stored procedures and functions, triggers and events

  • –events: event scheduler events
  • –routines: stored procedures and functions
  • –triggers: triggers for tables
    disabled by default
7.4.5.4 dumping table definitions and content separately
mysqldump --no-data test > dump-defs.sql

mysqldump --no-create-info test > dump-data.sql
7.4.5.5 using mysqldump to test for upgrade or downgrade incompatibilities

proc

mysqldump --all-databases --no-data --routines --events > dump-defs.sql

looking for warnings or errors while the dump file is being processed

proc

mysqldump --all-databases --no-create-info > dump-data.sql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值