Detailed explanation of the use of MySQL mysqldump

Detailed explanation of the use of MySQL mysqldump

1. Introduction to mysqldump

mysqldump is a logical backup tool that comes with MySQL.

Its backup principle is to connect to the MySQL database through the protocol, query the data that needs to be backed up, and convert the queried data into corresponding insert statements. When we need to restore these data, we only need to execute these insert statements to restore the corresponding data.

2. Backup Command

2.1 Command Format

mysqldump [options] database name [table name] > script name

or

mysqldump [options] --database name [options table name] > script name

or

mysqldump [options] --all-databases [options] > script name

2.2 Option Description

Parameter name abbreviation meaning
--host -h Server IP address
--port -P Server port number
--user -u MySQL Username
--pasword -p MySQL password
--databases Specify the database to back up
--all-databases Back up all databases on the mysql server
--compact Compressed mode, produces less output
--comments Add annotation information
--complete-insert Output the completed insert statement
--lock-tables Before backing up, lock all database tables
--no-create-db/--no-create-info Disable the generation of create database statements
--force Continue the backup operation even if an error occurs
--default-character-set Specifying the default character set
--add-locks Lock database tables while backing them up

2.3 Examples

Back up all databases:

mysqldump -uroot -p --all-databases > /backup/mysqldump/all.db

Back up the specified database:

mysqldump -uroot -p test > /backup/mysqldump/test.db

Back up the specified database and table (multiple tables are separated by spaces)

mysqldump -uroot -p mysql db event > /backup/mysqldump/2table.db

Back up the specified database excluding certain tables

mysqldump -uroot -p test --ignore-table=test.t1 --ignore-table=test.t2 > /backup/mysqldump/test2.db

3. Restore Command

3.1 System command line

mysqladmin -uroot -p create db_name 
mysql -uroot -p db_name < /backup/mysqldump/db_name.db

Note: Before importing the backup database, if db_name does not exist, it needs to be created; and it can only be imported if the database name is the same as the database name in db_name.db.

3.2 Source Method

mysql > use db_name
mysql > source /backup/mysqldump/db_name.db

Examples

Note: Username: root Password: DbPasswd The generated sql script is db.sql

Export the table structure of the database as DBName (without exporting data)

mysqldump -uroot -pDbPasswd -d DBName > db.sql

Export the table structure and all data of the database DBName (without adding -d)

mysqldump -uroot -pDbPasswd DBName > db.sql;

Export the structure of the table (test) of the database DBName

mysqldump -uroot -pDbPasswd -d DBName test > db.sql

Export the structure and all data of the table (test) of the database DBName (without adding -d)

mysqldump -uroot -pDbPasswd DBName test > db.sql 

This is the end of this article about the detailed use of MySQL mysqldump. For more relevant MySQL mysqldump content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • mysqldump parameters you may not know
  • Implementation of MySQL5.7 mysqldump backup and recovery
  • Detailed explanation of the idea of ​​using mysqldump+expect+crontab to implement mysql periodic cold backup in linux
  • Summary of MySql import and export methods using mysqldump
  • How to use mysqldump for full and point-in-time backups
  • Docker uses the mysqldump command to back up and export mysql data in the project
  • MySQL data migration using MySQLdump command
  • PHP scheduled backup MySQL and mysqldump syntax parameters detailed
  • Detailed explanation of how to use the mysql backup script mysqldump
  • Detailed explanation of Linux mysqldump exporting database, data, and table structure
  • Detailed discussion on the issue of mysqldump data export
  • Use of MySQL official export tool mysqlpump

<<:  Comparison of the efficiency of different methods of deleting files in Linux

>>:  uni-app implements NFC reading function

Recommend

Detailed explanation of mixins in Vue.js

Mixins provide distributed reusable functionality...

Analysis of Difficulties in Hot Standby of MySQL Database

I have previously introduced to you the configura...

A QQ chat room based on vue.js

Table of contents Introduction The following is a...

What is flex and a detailed tutorial on flex layout syntax

Flex Layout Flex is the abbreviation of Flexible ...

js to call the network camera and handle common errors

Recently, due to business reasons, I need to acce...

Method of iframe adaptation in web responsive layout

Problem <br />In responsive layout, we shou...

Creative About Us Web Page Design

Unique “About”-Pages A great way to distinguish yo...

Implementation of FIFO in Linux process communication

FIFO communication (first in first out) FIFO name...

MySQL 8.X installation tutorial under Windows

I had been using MySQL 5.7 before, but because My...

React event binding details

Table of contents Class component event binding F...

Javascript to achieve the drag effect of the login box

This article shares the specific code of Javascri...

Detailed explanation of the principle and function of Vue list rendering key

Table of contents The principle and function of l...

Pure CSS3 code to implement a running clock

Operation effectCode Implementation html <div ...

Optimization analysis of Limit query in MySQL optimization techniques

Preface In actual business, paging is a common bu...