Implementation of batch data import in MySQL

Source: Internet
Author: User

How can I import data in batches in MySQL? This is a problem that many people have mentioned. The following describes how to import data in batches in MySQL for your reference.

Whether in website development or application development, we often encounter the need to batch import data from a MySQL or MS SQLServer table to another table, you even need to specify the import field.

The following uses the MySQL database as an example to describe how to import all the data of a table or the data of a specified field to the target table through the SQL command line. This method also applies to SQLServer databases, that is, T-SQL.

Category 1: If the fields of the two exported tables are the same as those of the target table, and you want to insert all the data, you can use this method: This method is only suitable for exporting the two tables in the same database)

INSERT
Target table
SELECT * FROM
Source table
;
For example, to insert the articles table into the newArticles table, you can use the following SQL statement:

INSERT
NewArticles
SELECT * FROM
Articles
;
Type 2: If you only want to import specified fields, you can use this method:

INSERT
Target table (Field 1, Field 2 ,...)
SELECT
Field 1, Field 2 ,...
FROM
Source table
;
Note that the fields in the preceding two tables must be of the same field type). Otherwise, a Data Conversion error occurs.

1. Copy table data across servers

 
 
  1. Insert into openrowset ('sqloledb', 'localhost'; 'sa '; '20170101', Test. dbo. Table_ B)
  2. Select * from Test. dbo. Table_A
  3.  
  4. // Enable Ad Hoc Distributed Queries:
  5.  
  6. Exec sp_configure 'show advanced options', 1
  7. Reconfigure
  8. Exec sp_configure 'ad Hoc Distributed Queries ', 1
  9. Reconfigure
  10.  
  11. // After use, disable Ad Hoc Distributed Queries:
  12. Exec sp_configure 'ad Hoc Distributed Queries ', 0
  13. Reconfigure
  14. Exec sp_configure 'show advanced options', 0
  15. Reconfigure
  16.  

2,

 
 
  1. // Not cross-Server
  2. Insert into dbo. Table_ B) select * from dbo. Table_A

Concatenate the table name and database connection string with code and then execute the SQL statement program function you need.
 

In-depth study on MySQL's data deletion from multiple tables

Simple MySQL large table backup method

Combination of multiple MySQL table result sets

Implementation of MySQL table sharding

MySQL authorization table usage example

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.