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

Take you to understand MySQL character set settings in 5 minutes

Table of contents 1. Content Overview 2. Concepts...

Summary of common MySQL commands

Set change mysqlroot password Enter the MySQL dat...

The difference between Readonly and Disabled

To summarize: Readonly is only valid for input (te...

mysql calculation function details

Table of contents 2. Field concatenation 2. Give ...

JavaScript implements the detailed process of stack structure

Table of contents 1. Understanding the stack stru...

JS Canvas interface and animation effects

Table of contents Overview Canvas API: Drawing Gr...

Solutions to the failure and invalidity of opening nginx.pid

Table of contents 1. Problem Description 2. Probl...

Stop using absolute equality operators everywhere in JS

Table of contents Overview 1. Test for null value...

Detailed explanation of the command mode in Javascript practice

Table of contents definition structure Examples C...

Share some key interview questions about MySQL index

Preface An index is a data structure that sorts o...

How to use Docker Compose to implement nginx load balancing

Implement Nginx load balancing based on Docker ne...

Detailed introduction to nobody user and nologin in Unix/Linux system

What is the nobody user in Unix/Linux systems? 1....