mysql load 主键验证_MySQL
程序员文章站
2022-03-16 10:37:44
...
load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
1.如果id不是主键,会不停增加。
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
Query OK, 2 rows affected (0.02 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test;
+------+-----------+
| id | name |
+------+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
+------+-----------+
4 rows in set (0.00 sec)
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
Query OK, 2 rows affected (0.04 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test;+------+-----------+
| id | name |
+------+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
| 3 | wang-load |
| 4 | xia-load |
+------+-----------+
6 rows in set (0.00 sec)
2.如果id是主键,会skip
mysql> alter table test add PRIMARY KEY (id);
Query OK, 2 rows affected (0.38 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from test;+----+------+
| id | name |
+----+------+
| 1 | wang |
| 2 | xia |
+----+------+
2 rows in set (0.00 sec)
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
Query OK, 2 rows affected (0.05 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test;+----+-----------+
| id | name |
+----+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
+----+-----------+
4 rows in set (0.00 sec)
修改TXT文件
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';Query OK, 0 rows affected (0.00 sec)
Records: 2 Deleted: 0 Skipped: 2 Warnings: 0
mysql> select * from test;+----+-----------+
| id | name |
+----+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
+----+-----------+
4 rows in set (0.00 sec)
1.如果id不是主键,会不停增加。
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
Query OK, 2 rows affected (0.02 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test;
+------+-----------+
| id | name |
+------+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
+------+-----------+
4 rows in set (0.00 sec)
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
Query OK, 2 rows affected (0.04 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test;+------+-----------+
| id | name |
+------+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
| 3 | wang-load |
| 4 | xia-load |
+------+-----------+
6 rows in set (0.00 sec)
2.如果id是主键,会skip
mysql> alter table test add PRIMARY KEY (id);
Query OK, 2 rows affected (0.38 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from test;+----+------+
| id | name |
+----+------+
| 1 | wang |
| 2 | xia |
+----+------+
2 rows in set (0.00 sec)
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';
Query OK, 2 rows affected (0.05 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test;+----+-----------+
| id | name |
+----+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
+----+-----------+
4 rows in set (0.00 sec)
修改TXT文件
mysql> load data LOCAL infile '~/Documents/load_test.txt' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '/n';Query OK, 0 rows affected (0.00 sec)
Records: 2 Deleted: 0 Skipped: 2 Warnings: 0
mysql> select * from test;+----+-----------+
| id | name |
+----+-----------+
| 1 | wang |
| 2 | xia |
| 3 | wang-load |
| 4 | xia-load |
+----+-----------+
4 rows in set (0.00 sec)
上一篇: PHP之对象遍历
推荐阅读
-
php+MySQL实现登录时验证登录名和密码是否正确,mysql登录名_PHP教程
-
Customized MySQL LOAD DATA LOCAL INFILE handlers with libmys_MySQL
-
MySQL LOAD DATA INFILE
-
[MySQLCPU]线上飙升800%,load达到12的解决过程_MySQL
-
load data infile将excel文件中的数百万条数据在1分钟内导入数据_MySQL
-
php+MySQL实现登录时验证登录名和密码是否正确_php技巧
-
MySQL 5.5 DBA工具 多进程dump 多进程load 多进程备份还原 Pytho
-
mysql LOAD语句批量录入数据
-
Customized MySQL LOAD DATA LOCAL INFILE handlers with libmys_MySQL
-
1548-Cannot load from mysql.proc.The table is probably corru_MySQL