简体   繁体   中英

Import CSV or XML to MySQL

I have two huge databases in both formats CSV & XML, and I want to import to MySQL the databases.

I tried to used : LOAD DATA INFILE, but I receive this error message : ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

MySQL Version : 5.1.56-log

I tried without any success to use PHP to convert XML to array then Insert line by line.

EDIT :

I used this query as root to import XML to MySQL :

LOAD XML LOCAL FILE '/home/floupie/public_html/All.xml' INTO TABLE k_logs ;

This is the appropriate syntax for a csv load.

LOAD DATA LOCAL INFILE '/importfile.csv' 
INTO TABLE test_table 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
(field1, filed2, field3);

This is the appropriate syntax for an xml load.

LOAD XML LOCAL INFILE 'items.xml'
INTO TABLE item
ROWS IDENTIFIED BY '<item>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM