Solved

Script to append data into MySQL tables

Posted on 2011-03-03
1
935 Views
Last Modified: 2012-05-11
Hello,

Can you please review and provide suggestions if needed for my syntax to load data into a MySQL table without overwriting the data?  Please see my script below which I would run under mysql in command line....

--TBL_NAME
load data local infile 'tbl_name.txt'
append into table TBL_NAME
fields terminated by ':;:';
optimize table TBL_NAME;
0
Comment
Question by:cassie5643
1 Comment
 
LVL 3

Accepted Solution

by:
mwiercin earned 500 total points
ID: 35030225
Hi,

In MySQL LOAD DATA INFILE won't overwrite any data.

$ cat test.csv 
1,2
$

mysql> create table test_load ( c1 int , c2 int); 
Query OK, 0 rows affected (0.10 sec)

mysql> select * from test_load;
Empty set (0.00 sec)

mysql> load data local  infile 'test.csv' into table test_load fields terminated by ',' lines terminated by '';
Query OK, 1 row affected (0.00 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

mysql> select * from test_load;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    2 | 
+------+------+
1 row in set (0.00 sec)

mysql> load data local  infile 'test.csv' into table test_load fields terminated by ',' lines terminated by '';
Query OK, 1 row affected (0.00 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

mysql> select * from test_load;
+------+------+
| c1   | c2   |
+------+------+
|    1 |    2 | 
|    1 |    2 | 
+------+------+
2 rows in set (0.00 sec)

mysql> 

Open in new window

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question