How to Backup a MyISAM / InnoDB MySQL Database

Whichever MySQL storage engine you use, built in recovery is far from perfect and it’s only a matter of time until you’ll experience some corruption / data loss.

Plan ahead and implement daily or weekly backups of all data.

There are four primary ways to backup a MySQL database:

1. IBBackup

The recommended way to bakcup a MySQL database, is by using a script called InnoDBBackup by the makers of InnoDB.

Pros: Works with both MyISAM and InnoDB. Fast. Doesn’t lock tables
Cons: Takes a few hours to setup

2. MySQLDump

Available from the early days of MySQL, MySQLDump is a command line utility provided by MySQL that works very well

To run, use:

mysqldump –user=user –single-transaction –password=pass –opt DBNAME > dumpfile.sql

The –opt flag is very important. This is shorthand to pass in many flags at once; –add-drop-table –add-locks –create-options –disable-keys –extended-insert –lock-tables –quick –set-charset. This ensures that your database is in a good state while the backup is performed, including restricting all write access while the backup is in operation. Any locks placed will be automatically removed when this utility finishes.

The –single-transaction flag is important for InnoDB tables. It starts a transaction and prevents any changes to the data while backup is running, to maintain data consistency.

Pros: Works with all table types.
Cons: Locks tables. Your database will be inaccessible while backup is running.

Note: If your database only consists of MyISAM tables, consider using mysqlhotcopy. It’s faster, but doesn’t work with InnoDB tables.

3. File copy

Copy the entire /data MySQL folder

Pros: Very easy to setup
Cons: You have to manually shutdown the database BEFORE starting the file copy, otherwise the backup will faill

4. MySQL Replication

Read our step-by-step guide about how to setup MySQL replication

Pros: The replication server can double as a live database, for performance (master-slave) and uptime (master-master)
Cons: Takes a few hours to setup

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值