I've a table_name
like this:
No | Name | Inserted_Date | Inserted_By
=====================================
and then I've file name.csv like this
no,name
1,jhon
2,alex
3,steve
I want to load these file table_name
using syntax like this:
LOAD DATA INFILE 'name.csv' INTO TABLE table1
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
???
the question is, what should I put on ???
so I can store data like this:
No | Name | Inserted_Date | Inserted_By
=====================================
1 | jhon | sysdate() | me
2 | ales | sysdate() | me
3 | steve | sysdate() | me
The local_infile system variable controls server-side LOCAL capability. Depending on the local_infile setting, the server refuses or permits local data loading by clients that request local data loading. By default, local_infile is disabled. (This is a change from previous versions of MySQL.)
LOAD DATA (all forms) is more efficient than INSERT because it loads rows in bulk.
mysql> LOAD DATA LOCAL INFILE '/path/pet. txt' INTO TABLE pet; If you created the file on Windows with an editor that uses \r\n as a line terminator, you should use this statement instead: mysql> LOAD DATA LOCAL INFILE '/path/pet.
Open my. ini file with a text editor. Look for the headers [client] , [mysql] under the CLIENT section & [mysqld] under the SERVER section. Save the file and restart MySQL80 service under the Windows local services.
I do not understand if columns inserted_date
and inserted_by
already exists in your table. If no than you can add them before runing LOAD DATA INFILE
:
LOAD DATA INFILE 'name.csv' INTO TABLE table1
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(@no, @name)
set
no = @no,
name = @name,
inserted_date = now(),
inserted_by = 'me'
something like this will do it:
LOAD DATA INFILE 'name.csv' INTO TABLE table1
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
SET inserted_date=CURRENT_DATE(), inserted_by='me'
Take a look at the manual: http://dev.mysql.com/doc/refman/5.1/en/load-data.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With