mysql implements importing only a specified table from the sql file of exported data

mysql implements importing only a specified table from the sql file of exported data

Scenario

Yesterday the system automatically backed up all table data of a certain database, named dbAll.sql.gz. The file is large (e.g. 40G)

Today, we found a problem with a piece of data in tableA, and we need to check the changes of two records. The data of tableA needs to be retrieved from dbAll in order to compare the record.

Operational Scheme

1. Import dbAll.sql.gz into the database to be compared (temporary database), and then compare tableA. Not recommended because the amount of data is too large and it is time-consuming

2. After decompressing dbAll.sql.gz, use Java code to read the CREATE statements and INSERT statements about tableA in dbAll.sql into the file tableA.sql, and then import tableA.sql into the temporary database for comparison.

3. See (not tried): mysqldump exports the entire database alldb.sql. Can I only import one table when importing?

Method 1:

perl extract_sql.pl -t mytable -r mydumpfile > mytable.sql

Method 2:

cat test1db.sql | sed -n '/Table structure for table .test1./,/Table structure for table .test2./p'>/tmp/xxx.sql

Method 3:

awk '/Table structure for table .test1./,/Table structure for table .test2./{print}' src_bake_db.sql.gz > targetdb.sql

Method 3: Export the data of the test1 and test2 tables in the src_bake_db.sql.gz compressed file to targetdb.sql

Supplementary knowledge: The mysql command line exports the first 100 records of all tables in the entire database

As shown below:

mysqldump -uysp -pYspxxx db_name --where="1=1 limit 100" >/mnt/share/paxxx.com/backup.sql

Just run it directly on the command line without logging into the mysql client.

mysqldump -h server name -u account name -p database name --where="true limit 100"> /tmp/supports_launch.sql

phpmyadmin export php script:

http://local.phpmyadmin.com/export.php

The above MySQL implementation of importing only a specified table from the sql file of exported data is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of using mysqldump to export data from MySQL database
  • How to use mysqldump to backup and restore specified tables
  • Mysql command line import sql data
  • Detailed explanation of mysqldump backup and restore and mysqldump import and export statements

<<:  Vue implements small form validation function

>>:  Detailed explanation of the Docker deployment tutorial for Jenkins beginners

Recommend

Introduction to the use of this in HTML tags

For example: Copy code The code is as follows: <...

How to run Spring Boot application in Docker

In the past few days, I have studied how to run s...

How to use vs2019 for Linux remote development

Usually, there are two options when we develop Li...

Interpreting MySQL client and server protocols

Table of contents MySQL Client/Server Protocol If...

Detailed explanation of Vue-router nested routing

Table of contents step 1. Configure routing rules...

Install MySQL5.5 database in CentOS7 environment

Table of contents 1. Check whether MySQL has been...

js to make a simple calculator

This article shares the specific code of making a...

Vue realizes the whole process of slider drag verification function

Rendering Define the skeleton, write HTML and CSS...

How to restore a database and a table from a MySQL full database backup

In the official MySQL dump tool, how can I restor...

How to Delete Junk Files in Linux Elegantly

I wonder if you are like me, a programmer who arr...

Detailed explanation of MySQL execution plan

The EXPLAIN statement provides information about ...

Instructions for using the meta viewport tag (mobile browsing zoom control)

When OP opens a web page with the current firmwar...