Mysql database backup code

Source: Internet
Author: User
Tags mysql tutorial

Database Backup is what every WEB developer and database administrator must do. Today we want to talk about the logical backup in the mysql database and back up the database into a text file, let's talk about three database backup methods for all of you.

Database tutorial backupThis is what every WEB developer and database administrator must do. What we want to talk about today is the logical backup in the mysql tutorial database, which backs up the database into a text file, let's talk about three database backup methods for all of you.

1. Back up the specified database or some tables of the database.

Shell> mysqldump [options] db_name [tables]

2. Back up one or more databases

Shell> mysqldum [options] --- database db1 [db2 db3...]

Iii. Back up all databases

Shell> mysqldump [options] -- all-database

If no table is specified, all tables in the database are exported by default. Let's take a look at the mysqldump instance.

Back up all databases

[BKjia. c0m @ localhost ~] $ Mysqldump-uroot-p -- all-database> d: www. bKjia. c0m111cn. SQL;

Enter password: 123456;

Backup database test

[BKjia. c0m @ localhost ~] $ Mysqldump-uroot-p -- test> d: www. bKjia. c0m111cn. SQL;

Back up the table emp in database test;

[BKjia. c0m @ localhost ~] $ Mysqldump-uroot-p -- test emp> d: www. bKjia. c0m111cn. SQL;

All tables in the backup database test are separated by commas, as shown below:

[BKjia. c0m @ localhost ~] # Mysqldump-uroot-T/bKjia. c0m test emp -- fields-terminated-','

[BKjia. c0m @ localhost ~] # More emp.txt

1, z1

2, z2

3, z3

There are many options for mysqldump, which can be viewed with help.

Note: To ensureDatabase BackupConsistency. The myisam database storage engine needs to add the-l parameter during backup, indicating that all tables are locked. During the backup, all tables can only be read but cannot be updated. However, for innodb and dbd, we can use a better option -- single-transaction. This option award allows the innodb Storage engine to get a snapshot so that the backup database can be consistent.

The original tutorial on this site is reproduced and indicated by www. bKjia. c0m

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.