[英]How to LOAD DATA INLINE from ID 1 into MYSQL Table Column
I have a table topic which is having id and name id is primary.我有一个表主题,它有id和名称id 是主要的。 It has already data from ID 1 to 6.
它已经有从 ID 1 到 6 的数据。
I added one new column other .我添加了一个新的列other 。 I want to load data from list.txt file into it and that should be from ID 1 to 6.
我想从 list.txt 文件中加载数据,它应该是从 ID 1 到 6。
My list.txt is having:我的 list.txt 有:
apple
banana
orange
kiwi
My table:
CREATE TABLE `topics` (
`id` int(11) UNSIGNED NOT NULL,
`name` varchar(255) DEFAULT NULL,
`other` varchar(500) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO `topics` (`id`, `name`, `other`) VALUES
(1, 'Accessories', ''),
(2, 'Cover', ''),
(3, 'Logos', ''),
(4, 'Story', ''),
(5, 'Editing', ''),
(6, 'Gaming', '');
ALTER TABLE `topics`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `id` (`id`),
ADD KEY `name` (`name`);
ALTER TABLE `topics`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
I tried but it adds after 6.我试过了,但它在 6 之后添加。
LOAD DATA INFILE 'list.txt' INTO TABLE topics
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\r\n' (other);
it added from 7, instead I wanted it to be from 1它从 7 添加,而不是我希望它从 1
Load data infile is the equivalent of an INSERT and is behaving as expected.加载数据 infile 相当于 INSERT,并且按预期运行。 There is no update option.
没有更新选项。 I suggest you load to a staging table then UPDATE to target.
我建议您加载到暂存表,然后更新到目标。 I do foresee a problem though since there is no way of knowing which row to update in target.
我确实预见到一个问题,因为无法知道要更新目标中的哪一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.