Home Database Mysql Tutorial MySQL Dump_MySQL

MySQL Dump_MySQL

Jun 01, 2016 pm 01:11 PM

--all-databases  , -A

导出全部数据库。

mysqldump  -uroot -p --all-databases


--all-tablespaces  , -Y

导出全部表空间。

mysqldump  -uroot -p --all-databases --all-tablespaces


--no-tablespaces  , -y

不导出任何表空间信息。

mysqldump  -uroot -p --all-databases --no-tablespaces


--add-drop-database

每个数据库创建之前添加drop数据库语句。

mysqldump  -uroot -p --all-databases --add-drop-database


--add-drop-table

每个数据表创建之前添加drop数据表语句。(默认为打开状态,使用--skip-add-drop-table取消选项)

mysqldump  -uroot -p --all-databases  (默认添加drop语句)

mysqldump  -uroot -p --all-databases –skip-add-drop-table  (取消drop语句)


--add-locks

在每个表导出之前增加LOCK TABLES并且之后UNLOCK  TABLE。

默认为打开状态,使用--skip-add-locks取消选项

mysqldump  -uroot -p --all-databases  (默认添加LOCK语句)

mysqldump  -uroot -p --all-databases –skip-add-locks   (取消LOCK语句)


--allow-keywords

允许创建是关键词的列名字。这由表名前缀于每个列名做到。

mysqldump  -uroot -p --all-databases --allow-keywords


--apply-slave-statements

在'CHANGE MASTER'前添加'STOP SLAVE',并且在导出的最后添加'START SLAVE'。

mysqldump  -uroot -p --all-databases --apply-slave-statements


--character-sets-dir

字符集文件的目录

mysqldump  -uroot -p --all-databases  --character-sets-dir=/usr/local/mysql/share/mysql/charsets


--comments

附加注释信息。默认为打开,可以用--skip-comments取消

mysqldump  -uroot -p --all-databases  (默认记录注释)

mysqldump  -uroot -p --all-databases --skip-comments   (取消注释)


--compatible

导出的数据将和其它数据库或旧版本的MySQL 相兼容。值可以为ansi、mysql323、mysql40、postgresql、oracle、mssql、db2、maxdb、no_key_options、no_tables_options、no_field_options等,

要使用几个值,用逗号将它们隔开。它并不保证能完全兼容,而是尽量兼容。

mysqldump  -uroot -p --all-databases --compatible=ansi


--compact

导出更少的输出信息(用于调试)。去掉注释和头尾等结构。可以使用选项:--skip-add-drop-table  --skip-add-locks --skip-comments --skip-disable-keys

mysqldump  -uroot -p --all-databases --compact


--complete-insert,  -c

使用完整的insert语句(包含列名称)。

这么做能提高插入效率,但是可能会受到max_allowed_packet参数的影响而导致插入失败。

mysqldump  -uroot -p --all-databases --complete-insert


--compress, -C

在客户端和服务器之间启用压缩传递所有信息

mysqldump  -uroot -p --all-databases --compress


--create-options,  -a

在CREATE TABLE语句中包括所有MySQL特性选项。(默认为打开状态)

mysqldump  -uroot -p --all-databases


--databases,  -B

导出几个数据库。参数后面所有名字参量都被看作数据库名。

mysqldump  -uroot -p --databases test mysql

--debug

输出debug信息,用于调试。默认值为:d:t:o,/tmp/mysqldump.trace

mysqldump  -uroot -p --all-databases --debug

mysqldump  -uroot -p --all-databases --debug=” d:t:o,/tmp/debug.trace”

--debug-check

检查内存和打开文件使用说明并退出。

mysqldump  -uroot -p --all-databases --debug-check


--debug-info

输出调试信息并退出

mysqldump  -uroot -p --all-databases --debug-info


--default-character-set

设置默认字符集,默认值为utf8

mysqldump  -uroot -p --all-databases --default-character-set=latin1


--delayed-insert

采用延时插入方式(INSERT DELAYED)导出数据

mysqldump  -uroot -p --all-databases --delayed-insert


--delete-master-logs

master备份后删除日志. 这个参数将自动激活--master-data。

mysqldump  -uroot -p --all-databases --delete-master-logs


--disable-keys

对于每个表,用/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;和/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;语句引用INSERT语句。

这样可以更快地导入dump出来的文件,因为它是在插入所有行后创建索引的。该选项只适合MyISAM表,默认为打开状态。

mysqldump  -uroot -p --all-databases 


--dump-slave

该选项将导致主的binlog位置和文件名追加到导出数据的文件中。

设置为1时,将会以CHANGE MASTER命令输出到数据文件;

设置为2时,在命令前增加说明信息。该选项将会打开--lock-all-tables,除非--single-transaction被指定。

该选项会自动关闭--lock-tables选项。

默认值为0。

mysqldump  -uroot -p --all-databases --dump-slave=1

mysqldump  -uroot -p --all-databases --dump-slave=2


--events, -E

导出事件。

mysqldump  -uroot -p --all-databases --events


--extended-insert,  -e

使用具有多个VALUES列的INSERT语法。

这样使导出文件更小,并加速导入时的速度。

默认为打开状态,使用--skip-extended-insert取消选项。

mysqldump  -uroot -p --all-databases

mysqldump  -uroot -p --all-databases--skip-extended-insert   (取消选项)


--fields-terminated-by

导出文件中忽略给定字段。

与--tab选项一起使用,不能用于--databases和--all-databases选项

mysqldump  -uroot -p test test --tab=”/home/mysql” --fields-terminated-by=”#”


--fields-enclosed-by

输出文件中的各个字段用给定字符包裹。与--tab选项一起使用,不能用于--databases和--all-databases选项

mysqldump  -uroot -p test test --tab=”/home/mysql” --fields-enclosed-by=”#”


--fields-optionally-enclosed-by

输出文件中的各个字段用给定字符选择性包裹。

与--tab选项一起使用,不能用于--databases和--all-databases选项

mysqldump  -uroot -p test test --tab=”/home/mysql”  --fields-enclosed-by=”#” --fields-optionally-enclosed-by  =”#”


--fields-escaped-by

输出文件中的各个字段忽略给定字符。

与--tab选项一起使用,不能用于--databases和--all-databases选项

mysqldump  -uroot -p mysql user --tab=”/home/mysql” --fields-escaped-by=”#”


--flush-logs

开始导出之前刷新日志。

请注意:假如一次导出多个数据库(使用选项--databases或者--all-databases),将会逐个数据库刷新日志。

除使用--lock-all-tables或者--master-data外。

在这种情况下,日志将会被刷新一次,相应的所以表同时被锁定。

因此,如果打算同时导出和刷新日志应该使用--lock-all-tables 或者--master-data 和--flush-logs。

mysqldump  -uroot -p --all-databases --flush-logs


--flush-privileges

在导出mysql数据库之后,发出一条FLUSH  PRIVILEGES 语句。为了正确恢复,该选项应该用于导出mysql数据库和依赖mysql数据库数据的任何时候。

mysqldump  -uroot -p --all-databases --flush-privileges


--force

在导出过程中忽略出现的SQL错误。

mysqldump  -uroot -p --all-databases --force


--help

显示帮助信息并退出。

mysqldump  --help


--hex-blob

使用十六进制格式导出二进制字符串字段。如果有二进制数据就必须使用该选项。影响到的字段类型有BINARY、VARBINARY、BLOB。

mysqldump  -uroot -p --all-databases --hex-blob

--host, -h

需要导出的主机信息

mysqldump  -uroot -p --host=localhost --all-databases

--ignore-table

不导出指定表。指定忽略多个表时,需要重复多次,每次一个表。每个表必须同时指定数据库和表名。例如:--ignore-table=database.table1 --ignore-table=database.table2 ……

mysqldump  -uroot -p --host=localhost --all-databases --ignore-table=mysql.user


--include-master-host-port

在--dump-slave产生的'CHANGE  MASTER TO..'语句中增加'MASTER_HOST=,MASTER_PORT='  

mysqldump  -uroot -p --host=localhost --all-databases --include-master-host-port


--insert-ignore

在插入行时使用INSERT IGNORE语句.

mysqldump  -uroot -p --host=localhost --all-databases --insert-ignore


--lines-terminated-by

输出文件的每行用给定字符串划分。与--tab选项一起使用,不能用于--databases和--all-databases选项。

mysqldump  -uroot -p --host=localhost test test --tab=”/tmp/mysql”  --lines-terminated-by=”##”


--lock-all-tables,  -x

提交请求锁定所有数据库中的所有表,以保证数据的一致性。这是一个全局读锁,并且自动关闭--single-transaction 和--lock-tables 选项。

mysqldump  -uroot -p --host=localhost --all-databases --lock-all-tables

--lock-tables,  -l

开始导出前,锁定所有表。用READ  LOCAL锁定表以允许MyISAM表并行插入。对于支持事务的表例如InnoDB和BDB,--single-transaction是一个更好的选择,因为它根本不需要锁定表。

请注意当导出多个数据库时,--lock-tables分别为每个数据库锁定表。因此,该选项不能保证导出文件中的表在数据库之间的逻辑一致性。不同数据库表的导出状态可以完全不同。

mysqldump  -uroot -p --host=localhost --all-databases --lock-tables


--log-error

附加警告和错误信息到给定文件

mysqldump  -uroot -p --host=localhost --all-databases  --log-error=/tmp/mysqldump_error_log.err


--master-data

该选项将binlog的位置和文件名追加到输出文件中。如果为1,将会输出CHANGE MASTER 命令;如果为2,输出的CHANGE  MASTER命令前添加注释信息。该选项将打开--lock-all-tables 选项,除非--single-transaction也被指定(在这种情况下,全局读锁在开始导出时获得很短的时间;其他内容参考下面的--single-transaction选项)。该选项自动关闭--lock-tables选项。

mysqldump  -uroot -p --host=localhost --all-databases --master-data=1;

mysqldump  -uroot -p --host=localhost --all-databases --master-data=2;

--max_allowed_packet

服务器发送和接受的最大包长度。

mysqldump  -uroot -p --host=localhost --all-databases --max_allowed_packet=10240


--net_buffer_length

TCP/IP和socket连接的缓存大小。

mysqldump  -uroot -p --host=localhost --all-databases --net_buffer_length=1024


--no-autocommit

使用autocommit/commit 语句包裹表。

mysqldump  -uroot -p --host=localhost --all-databases --no-autocommit


--no-create-db,  -n

只导出数据,而不添加CREATE DATABASE 语句。

mysqldump  -uroot -p --host=localhost --all-databases --no-create-db


--no-create-info,  -t

只导出数据,而不添加CREATE TABLE 语句。

mysqldump  -uroot -p --host=localhost --all-databases --no-create-info


--no-data, -d

不导出任何数据,只导出数据库表结构。

mysqldump  -uroot -p --host=localhost --all-databases --no-data


--no-set-names,  -N

等同于--skip-set-charset

mysqldump  -uroot -p --host=localhost --all-databases --no-set-names


--opt

等同于--add-drop-table,  --add-locks, --create-options, --quick, --extended-insert, --lock-tables,  --set-charset, --disable-keys 该选项默认开启,  可以用--skip-opt禁用.

mysqldump  -uroot -p --host=localhost --all-databases --opt

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

See all articles