Backup database with mysqldump

mysqldump is a sql-level backup mechanism, which converts data tables into sql script files, and is a very common backup method.

The usage of mysqldump and several commonly used parameters are listed below.

Basic usage:

mysqldump -u用户名 -p密码 -h主机 数据库 表 > 文件名

If you want to export the entire library, just do not add the table name.

example:

mysqldump -uroot -h10.1.153.23 achievement black > black.dump


Common options:
1. --all-databases
export all databases
Example:

mysqldump -uroot -h10.1.153.23 --all-databases > all.dump


2.--default-character-set=name
It is best to add this option when importing and exporting the default character set
. I have encountered importing data between different versions of mysql. Because this option is not added, sql is prompted when importing There are grammatical errors.
example:

mysqldump -uroot -h10.1.153.23 --default-character-set=utf8 achievement black > black.dump


3. The data exported by --complete-insert
adopts the complete INSERT method including the field name.
Example:
If this option is not added, one of the exported data is in the following form:

INSERT INTO `category` VALUES (1,'动作','2012-07-20 04:12:23');

After adding this option, the form of this data in the dump file is as follows:

INSERT INTO `category` (`id`, `name`, `ctime`) VALUES (1,'动作','2012-07-20 04:12:23');

Possible application scenario:
Import the data of the category table in the A library into the B library, but a new validate field has been added to the category table of the B library. At this point, the category table of library A cannot be imported into the category table of library B if the --complete-insert option is not added to mysqldump, and an error of different number of columns will be prompted.

4. --no-create-info
only exports data without adding a CREATETABLE statement

5. --where

Export data by where condition
Example:

mysqldump -uroot -h10.1.153.22 hao_game category --where "validate=2"

Only export data with a validate of 2.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324116330&siteId=291194637