gpt4 book ai didi

mysql - 如何从 mysql 中的文件插入到我的表中?

转载 作者:行者123 更新时间:2023-11-29 12:19:03 25 4
gpt4 key购买 nike

我有一个 file.dat 如下:

"Evan","E","Wallis","222222200","1958-01-16","134 Pelham, Milwaukee, WI","M","92000.00",null,"7"
"Jared","D","James","111111100","1966-10-10","123 Peachtree, Atlanta, GA","M","85000.00",null,"6"

我想将这些值插入到我的表中。

我尝试了以下方法,但没有成功。

LOAD DATA LOCAL INFILE "C:/file.dat" 
INTO TABLE table
;

没有错误,但有警告,并且表未填充数据。

LOAD DATA LOCAL INFILE "C:/file.dat" INTO TABLE table
0 row(s) affected, 64 warning(s):
1265 Data truncated for column 'fname' at row 1
1261 Row 1 doesn't contain data for all columns...

以下是的创建方式。

CREATE TABLE table(
fname varchar(15) not null,
minit varchar(1),
lname varchar(15) not null,
ssn char(9),
bdate date,
address varchar(50),
sex char,
salary decimal(10,2),
superssn char(9),
dno integer(4),
primary key (ssn),
foreign key (superssn) references employee(ssn)
);

最佳答案

默认情况下,MySQL 正在寻找制表符分隔的文件。请尝试以下操作:

LOAD DATA LOCAL INFILE "C:/file.dat" 
INTO TABLE table
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
;

关于mysql - 如何从 mysql 中的文件插入到我的表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29321024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com