Mysql 将文本文件中的数据加载到数据库中的表中

Mysql 将文本文件中的数据加载到数据库中的表中,mysql,sql,Mysql,Sql,有人能告诉我我做错了什么吗?首先我用外键创建了一些表,然后尝试从文本文件导入数据,并且有各种错误,但没有得到数据,所以现在我试图创建表加载数据,然后添加外键,希望可以工作,但是这也不是我所做的 create table Books ( ISBN Char(10) not null, Title Varchar(50) not null, Price Decimal(5,2) null, Authors Varchar(50) null, Pages int null, PubYear int n

有人能告诉我我做错了什么吗?首先我用外键创建了一些表,然后尝试从文本文件导入数据,并且有各种错误,但没有得到数据,所以现在我试图创建表加载数据,然后添加外键,希望可以工作,但是这也不是我所做的

create table Books (
ISBN Char(10) not null,
Title Varchar(50) not null,
Price Decimal(5,2) null,
Authors Varchar(50) null,
Pages int null,
PubYear int null,
QTY int null,
Constraint Books_PK primary key(ISBN)
);



create table customers (
customerid int not null,
company varchar(30) null,
firstname varchar(30) null,
lastname varchar(30) null,
street varchar(50) null,
city varchar(30) null,
state char(2) null default 'NE',
zip char(5) null,
phone char(10) null,
constraint customer_pk primary key(customerid)
);

create table orders (
orderid int not null,
customerid int not null,
orderdate date null,
shipdate date null,
shipping decimal(5,2) null,
salestax decimal(5,2) null,
constraint order_pk primary key(orderid)
);

create table orderinfo (
orderid int not null,
isbn char(10) not null,
qty int not null,
price decimal(5,2) not null,
detailid int not null auto_increment,
constraint orderinfo_pk primary key(detailid)
);

load data infile 'C:/lab8/books.txt
into table books;
它给了我一个错误,即数据对于第1行的ISBN列太长

文本文件的内容是

0929306279,  Bell labs,  29.95,  Gehani,  269,  2008,  121
0929306260,  Java,  49.95,  Sahni & Kumar,  465,  2008,  35
0670031844,  White Mughals,  34.95,  Dalrymple,  459,  2008,  78
0439357624,  Born Confused,  16.95,  Hidier,  432,  2007,  11

很明显,ISBN是10个字符,那么为什么它不进入表中呢?

如果你有
作为分隔符,你必须这样说

load data infile 'C:/lab8/books.txt'
into table books
fields terminated by ',';
根据,默认为制表符
\t

如果不指定FIELDS或LINES子句,则默认值与编写以下内容时相同:

字段以“\t”结尾并由“\\”转义的“”括起
以“\n”结尾并以“”开头的行


我使用MySQL 5.1oh是的,我忘了把它放在那里了。我以前在做外键的时候遇到了所有问题,但这次没有做。我知道这一定是心不在焉的事情。谢谢。现在希望当我获得表中的所有数据时,外键可以工作。因此它将默认下一行或下一行,这是一个新行,但\t是什么意思?@dsquaredtech'\t'表示制表器。在中,您将找到“特殊字符转义序列”表,其中列出了所有这些字符。我据此修正了答案。