I have a 350MB file named text_file.txt
containing this tab delimited data:
345868230 1646198120 1531283146 Keyword_1531283146 1.55 252910000
745345566 1646198120 1539847239 another_1531276364 2.75 987831000
...
MySQL Database name: Xml_Date
Database table: PerformanceReport
I have already created the table with all the destination fields.
I want to import this text file data into a MySQL. I googled and found some commands like LOAD DATA INFILE
and quite confused on how to use it.
How can I import this text file data?
It should be as simple as...
By default
LOAD DATA INFILE
uses tab delimited, one row per line, so should take it in just fine.The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed.
If the data file looks like this:
The resulting rows will be ("abc",1) and ("def",2). The third row in the file is skipped because it does not contain the prefix.
You can also load data files by using the mysqlimport utility; it operates by sending a LOAD DATA INFILE statement to the server
You should set the option:
into your [mysql] entry of my.cnf file or call mysql client with the --local-infile option:
You have to be sure that the same parameter is defined into your [mysqld] section too to enable the "local infile" feature server side.
It's a security restriction.
For me just adding the "LOCAL" Keyword did the trick, please see the attached image for easier solution.
My attached image contains both use cases:
(a) Where I was getting this error. (b) Where error was resolved by just adding "Local" keyword.
Walkthrough on using MySQL's LOAD DATA command:
Create your table:
Create your tab delimited file (note there are tabs between the columns):
Use the load data command:
If you get a warning that this command can't be run, then you have to enable the
--local-infile=1
parameter described here: How can I correct MySQL Load ErrorThe rows get inserted:
Check if it worked:
How to specify which columns to load your text file columns into:
Like this:
The file contents get put into variables @col1, @col2, @col3. myid gets column 1, and mydecimal gets column 3. If this were run, it would omit the second row: