Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1082
  • Last Modified:

Script to append data into MySQL tables

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
cassie5643
Asked:
cassie5643
1 Solution
 
mwiercinCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now