Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BULK INSERT in MYSQL

Tags:

On MS SQL, I can do bulk insert using the sql command below:

BULK INSERT myDatabase.MyTable FROM 'C:\MyTextFile.txt' WITH  FIELDTERMINATOR = ',' 

Now I want to do the same on MySQL but I can't seem to figure out how this works and what query to use.

like image 362
Ruben_PH Avatar asked Jan 15 '13 02:01

Ruben_PH


People also ask

What is bulk insert in MySQL?

The INSERT statement in MySQL also supports the use of VALUES syntax to insert multiple rows as a bulk insert statement. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas.

How can insert 1000 records at a time in MySQL?

MySQL INSERT multiple rows statement In this syntax: First, specify the name of table that you want to insert after the INSERT INTO keywords. Second, specify a comma-separated column list inside parentheses after the table name. Third, specify a comma-separated list of row data in the VALUES clause.

How can I insert more than 1000 rows in MySQL?

Or you can go to Edit -> Preferences -> SQL Editor -> SQL Execution and set the limit on Limit Rows Count.

Is bulk insert a transaction?

BulkInsert doesn't create a transaction by default. If you want to save multiple lists, you will need to handle the transaction in your code.


1 Answers

In MySQL, the equivalent would be

LOAD DATA INFILE

http://dev.mysql.com/doc/refman/5.1/en/load-data.html

LOAD DATA INFILE 'C:\MyTextFile' INTO TABLE myDatabase.MyTable FIELDS TERMINATED BY ',' 
like image 180
Eric J. Avatar answered Oct 25 '22 10:10

Eric J.