load-data-infile

mysql load data local infile syntax issues with set fields

China☆狼群 提交于 2019-12-11 09:08:21
问题 I'm trying to use mysql's LOAD DATA LOCAL INFILE syntax to load a .csv file into an existing table. Here is one record from my .csv file (with headers): PROD, PLANT,PORD, REVN,A_CPN, A_CREV,BRDI, DTE, LTME 100100128144,12T1,2070000,04,3DB18194ACAA,05_01,ALA13320004,20130807,171442 The issue is that I want 3 extra things done during import: A RECORDID INT NOT NULL AUTO_INTEGER PRIMARY_KEY field should be incremented as each row gets inserted (this table column and structure already exists

Importing CSV to MySQL with Load Data Infile

时光毁灭记忆、已成空白 提交于 2019-12-11 08:55:24
问题 I'm trying to load a CSV file into MySQL, and I keep getting syntax errors: load data infile 'c:/worldminwage.csv' fields terminated by ',' enclosed by '"' lines terminated by '\n' (YearlyWage, PercentGDP, Date effective); Can anyone help me get this working? Thanks. 回答1: Valid syntax is LOAD DATA INFILE 'c:/worldminwage.csv' INTO TABLE tablename . You forgot to mention which table the data should go in. See LOAD DATA INFILE Syntax 回答2: I think This would be more batter LOAD DATA INFILE 'c:

load data infile error: MySQL throws a syntax error when specifying columns

杀马特。学长 韩版系。学妹 提交于 2019-12-11 04:55:52
问题 StackOverflowers! I have an issue when trying to import a .csv file into a table. As far as I know (and as I've read in the reference manual), the syntax is something like this: load data infile '/path/to/my/file.csv' into table myTable(field1, field2, field3,..., fieldk) fields terminated by ',' optionally enclosed by '"' lines terminated by '\n' ignore 1 lines; However, MySQL client throws this error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that

mysql load data local infile

点点圈 提交于 2019-12-11 02:06:15
问题 I'm trying to load data into a mysql table using LOAD DATA LOCAL INFILE using the code below. Mysql: LOAD DATA INFILE '/var/www/vhosts/domain.com/httpdocs/test1.csv' INTO TABLE temp_table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (recloc,client_acc) Edit: changed LOAD DATA LOCAL INFILE to LOADA DATA INFILE, removed SET id=null, added IGNORE 1 LINES I'm getting no errors and no imported records. I believe the issue is related to the column names but i

Load XML Update Table--MySQL

夙愿已清 提交于 2019-12-07 20:14:48
问题 LOAD XML LOCAL INFILE 'file1.xml' INTO TABLE my_table ROWS IDENTIFIED BY '<product>'" Is it possible to use this function to update a table? I used REPLACE INTO TABLE my_table but that only added new rows and it did not update the existing rows. 回答1: LOAD XML LOCAL INFILE 'file1.xml' REPLACE INTO TABLE my_table ROWS IDENTIFIED BY '<product>'" See: http://dev.mysql.com/doc/refman/5.5/en/load-xml.html Note that: REPLACE works exactly like INSERT, except that if an old row in the table has the

Is there a way to populate a MySQL 5.7 table with data from a json file with line breaks on Win7?

ⅰ亾dé卋堺 提交于 2019-12-07 18:10:00
问题 I have following example json file and I'm trying to populate a MySQL table with it. Since MySQL 5.7 supports json as a native datatype I thought this shouldn't be a problem, but MySQL's json validator seems to have a problem with the line breaks inside the file. As soon as I get rid of all line breaks and write my example file in one line, it works perfectly. [ { "somestuff": [ { "field1": "val1", "field2": 17, "field3": 27, "field4": 42, "field5": 73 }, { "field1": "val2", "field2": 3,

Cannot load data to MySQL database with LOAD DATA INFILE

别来无恙 提交于 2019-12-07 13:35:47
问题 I am using LAMP in Ubuntu 12.04. I created a new user in MySQL (myserver@localhost) and granted ALL on a database to that user. There is a text file the permission of which is set to read for everyone. But when I try to load the data from that text file to the database, it says "Access denied for user 'myserver'@'localhost' (using password: YES)" The query I used is: LOAD DATA INFILE "~/text/member_info.txt" INTO TABLE member FIELDS TERMINATED BY '|'; I can think of a workaround with some

How to convert date in .csv file into SQL format before mass insertion

寵の児 提交于 2019-12-07 04:57:00
问题 I have a csv file with a couple thousand game dates in it, but they are all in the MM/DD/YYYY format 2/27/2011,3:05 PM,26,14 (26 and 14 are team id #s), and trying to put them into SQL like that just results in 0000-00-00 being put into the date field of my table. This is the command I tried using: LOAD DATA LOCAL INFILE 'c:/scheduletest.csv' INTO TABLE game FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (`date`, `time`, `awayteam_id`, `hometeam_id`); but again, it wouldn't

Problems with MySQL LOAD XML INFILE

孤人 提交于 2019-12-06 05:45:48
问题 I have a XML document in the format of... <?xml version="1.0" encoding="UTF-8"?> <yahootable> <row> <various><![CDATA[ multiline text, "&" other <stuff> ]]> </various> <id>1</id> <message><![CDATA[ sdfgsdfg dsfsdfsd ]]> </message> </row> <yahootable> ...and want to use MySQL's LOAD XML LOCAL INFILE to insert it into a table with columns; (various, id, message). I can't seem to get any data from the unparsed CDATA tags into the database columns. Is it that the data between CDATA tags is

load data infile, dealing with fields with comma

扶醉桌前 提交于 2019-12-06 05:19:04
问题 How do we deal with field with comma when using load data infile? i have this query: $sql = "LOAD DATA LOCAL INFILE '{$file}' INTO TABLE sales_per_pgs FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES (@user_id, @account_code, @pg_code, @sales_value) SET user_id = @user_id, account_code = @account_code, product_group_code = @pg_code, sales_value = REPLACE(@sales_value, ',', ''), company_id = {$company_id}, year = {$year}, month = {$month}"; and a line from the csv looks like