Domanda

I need to load a text file tabDelimited/csv directly into mysql as table. I am following the page (https://dev.mysql.com/doc/refman/5.5/en/loading-tables.html) for doing the same.

testfile.txt

field1,field2
"abc",1
"def",2
"ghi",3

However, I keep getting the following message:

mysql> LOAD DATA INFILE 'testfile.txt' INTO TABLE myTable IGNORE 1 LINES;
ERROR 1146 (42S02): Table 'test.myTable' doesn't exist

I see that 'load' can be used only after creating the table. So the error is expected. I have multiple files and I need to avoid creating tables one by one. Is there any other way to do the same.

È stato utile?

Soluzione

You need to create the table before you insert data into it.

If you have multiple files, create the table once, then append data using several LOAD DATA INFILE calls.

MySQL cannot automatically determine the schema of your data from a CSV file. Creating the table is essential for establishing the data type of the columns and any indexes or keys.

Altri suggerimenti

It sounds like you don't have the table created yet.

Just an example that you can bend to your needs. create table if not exists (field1 VARCHAR(3), field2 INTEGER);

Full documentation on create table: http://dev.mysql.com/doc/refman/5.1/en/create-table.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top