Home >Database >Mysql Tutorial >How to Perform Bulk Inserts in MySQL?

How to Perform Bulk Inserts in MySQL?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-11 19:52:03305browse

How to Perform Bulk Inserts in MySQL?

BULK INSERT in MySQL

Similar to the BULK INSERT command in MS SQL, MySQL provides the LOAD DATA INFILE command to perform bulk insertion operations.

Equivalent MySQL Command for BULK INSERT:

LOAD DATA INFILE

Syntax:

LOAD DATA INFILE 'filepath'
INTO TABLE database_name.table_name
FIELDS TERMINATED BY ','

Explanation:

  • filepath: The absolute or relative path of the text file containing the data to be inserted.
  • database_name.table_name: The full table name where the data will be inserted.
  • FIELDS TERMINATED BY ',': Specifies the character used as the field separator in the text file.

Example:

To load data from a text file named MyTextFile.txt into a table named MyTable in the database myDatabase, use the following command:

LOAD DATA INFILE 'C:\MyTextFile.txt'
INTO TABLE myDatabase.MyTable
FIELDS TERMINATED BY ','

The above is the detailed content of How to Perform Bulk Inserts in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn