Skip to content
Advertisement

CSV to MySQl Import

i need to insert csv into mysql database in proper column.

let say csv has header and then data A B C

and Mysql has table with column C A B

i need to know best way to insert csv data to mysql table

Advertisement

Answer

I believe you can use the following syntax for mysql:

"INSERT INTO users (username, password, email, firstName, lastName, createDate) VALUES ('test', 'test', 'test', 'test', 'test', 'test')"

So you can build up your query, using the header and the column it falls into, like so (pseudocode):

"Insert into table (header1, header2, header3) values (column1, column2, column3)"

Regardless of what order the data is in the table, that will insert data into the correct column.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement