mysqldump的使用_MySQL
mysqldump
mysql 提供了msyqldump 工具来导出数据库。
大致搜索了下网上的文章大都是出自一篇文章,内容繁多而杂。大多数都没有用到。
整理了一下自己用到过和觉得有用一些选项,记录于下。
mysqldump的基本使用格式为 :
mysqldump -hhost -Pport -uuser -ppassword dbname > xxxx.sql
host port可以不填,host默认localhost port默认为3306
以下为选项
--all-database,-A 导出全部该连接上全部数据包括创建数据库,创建表, 数据和存储过程
mysqldump -uroot -p -all-database > my.sql
--databases,-B 导出多个数据库的数据 使用这个选项sql文件中会有CREATE DATABASE
mysqldump -uroot -p --databases A B C > my.sql
mysqldump -uroot -p A > my.sql (这个不会有CREATE DATABASE语句)
--no-data, -d 只导结构
--no-create-info,-t 只导数据
--routines,-R 额外导出存储过程和函数(只使用这个选项还会生成其他表的信息)
如果只想导出存储过程和函数那么:
mysqldump -uroot -p --routines --no-data --no-create-info A> procedure.sql
导出的存储过程包含有DEFINER的信息,如果移植到其它机器上可能会有权限问题。
--extended-insert,-e 导出数据时使用一个多值的INSERT 语句,就是只会生成一条语句(默认)
--skip-extended-insert 和上一条相反,每一行一个INSERT 语句。
--complete-insert,-c 导出的INSERT语句会有字段名字,当表增加了列的时候比较好用
--add-locks 对导出的INSERT语句增加锁表的句子(默认开启)。像这样:
LOCK TABLE xxxx
INSERT INTO xxxx VALUES yyyy
UNLOCK TABLE xxxx
--skip-add-locks 上一条相反,不加锁定句子。
--add-drop-database 在创建数据库句子前 添加DROP DATABASE句子
--add-drop-tables 在创建表句子前添加DROP TABLE句子(默认)
--quick,-q 取消缓冲,直接输出到标准输出。 在导比较大的表需要加上。可以加快导出速度。
--single-transaction 在对支持事务的引擎(InnoDB)在导出之前提交事务以锁定全表。
--lock-tables 在不支持事务的引擎(MyISAM)在导出之前如果要锁定全表用这个选项。(也支持InnoDB,只是对于支持事务的引擎建议使用--single-transaction)
--hex-blob 用16进制的形式导出二进制数据
额外选项:
--no-defaults 如果在WIN上运行mysqldump时报错 unkown option '--no-beep' 可以加上这个选项。linux上没有这个问题。(原因没有深究,应该是某个配置文件里有这个选项,需要去掉)
--triggers 触发器,个人没有使用过, 使用方法同 --routines,这里就不提及。
以上就是最经常使用的选项.
(linux上或者在WIN上不报错可以省略 --no-defaults选项)
导出一个完整的数据库结构:
mysqldump --no-defaults -uroot -p --add-drop-database --no-data --routines -B A > my.sql
导出一个完整数据库结构和数据:
mysqldump --no-defaults -uroot -p --add-drop-database --routines --skip-extended-insert --skip-add-locks --quick --hex-blob -B A > my.sql
另外一个的就是备份整个数据库:
mysqldump --no-defaults -A > my.sql
P.S.
以上语句都没有锁表,需要看情况增加锁表选项。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.
