简体   繁体   English

如何将 ID 1 的 DATA INLINE 加载到 MYSQL 表列中

[英]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.

相关问题 如何将列名,数据从文本文件加载到MySQL表中? - How to load column names, data from a text file into a MySQL table? MySQL如何从一列中获取数据并以相同的ID和相同的表放入另一列 - MySQL how to take data from one column and put to another column under same ID and same table 如何在 MYSQL 中自动将值从一个表列加载到另一列 - How to automatically load values from one table column to another in MYSQL MySQL如何使用Substring从一列中提取数据并将其放入同一个表中相同ID下的另一列 - MySQL how to extract data from one column using Substring and put to another column under same ID within same table Mysql为表的现有列加载数据 - Mysql Load Data for existing column of a table 如何使用不相关表中的列数据更新列-MySQL - How to update a column with column data from an unrelated table - MySQL MySql中如何将列数据从一张表复制到另一张表? - How to Copy Column data from one table to another table in MySql? 如何根据mysql中的客户id显示两个表中的数据 - How to display data from two table according to customer id in mysql 如何将文件加载到特定表的mysql表中? - how to load a file into a mysql table for a particular column? PHP MySQL:从一列获取数据,但使用单独表中不同列的id - PHP MySQL: Get data from one column but by using id from different columns in separate table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM