LOAD DATA
語法的匯入功能,先找到上一節匯出的 dump1.txt。
[root@kvm3 ~]# find /tmp/systemd-private-* -name dump1.txt /tmp/systemd-private-0a153b804a324bf49246a6dd422cc22b-mariadb.service-3gFnjh/tmp/dump1.txt
--local
,才能讀取指定的檔案,否則 mysqlimport 會到 server 預設位置找檔案。
[root@kvm3 ~]# mysqlimport -uroot -p123qwe --local dyw \ $(find /tmp/systemd-private-* -name dump1.txt) mysqlimport: Error: 1146, Table 'dyw.dump1' doesn't exist, when using table: dump1
[root@kvm3 ~]# cp $(find /tmp/systemd-private-* -name dump1.txt) animals.txt
[root@kvm3 ~]# mysqlimport -uroot -p123qwe --local dyw animals.txt dyw.animals: Records: 4 Deleted: 0 Skipped: 4 Warnings: 4 [root@kvm3 ~]# mycli -uroot -p123qwe
[root@kvm3 ~]# mariadb -uroot -p123qwe -e "select * from dyw.animals;" +----+---------+------+ | id | name | foot | +----+---------+------+ | 1 | dog | 4 | | 2 | cat | 4 | | 3 | chicken | 2 | | 15 | bird | 2 | +----+---------+------+
auto_increment
,要匯入的紀錄 id 重複,所以跳過。
[root@kvm3 ~]# mariadb -uroot -p123qwe -e "desc dyw.animals;" +-------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(20) | NO | | NULL | | | foot | tinyint(3) unsigned | NO | | NULL | | +-------+---------------------+------+-----+---------+----------------+