Solved

Script to append data into MySQL tables

Posted on 2011-03-03
1
986 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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