将word(纯文本)和excel数据导入mysql数据库步骤

excelMySQLword

1个回答

写回答

853212

2025-10-17 14:26

+ 关注

excel
excel

load data infile /path/to/file into table 表名 #fields terminated by \t enclosed by '' escaped by \ #lines terminated by \n#(字段来自来1,字段2,字段3 ...)#ignore 1 lines

#如果是excel,可以直接写上源load data infile /path/to/file into table 表名 ,后两行不用写。

#word的话最好复制到txt,然后每个字段用制表符分开。用其他分隔符也可以,比如用逗号分隔字段,只要把fields terminated by \t 改成 ,就好了。

word
word

#如果文件内的字符串没有用双引号括起来,那就不写enclosed by ''。(这里的情况比较复杂,有时非字符串字段没有引号,就要用到optionally)

#还有一点是文件中的每列顺序要与表中字段顺序一致(不一致时还得在SQL后面加字段名)

#最后,看文件第一行是不是字段名,如果是,要么删去第一行,要么在SQL后面中加入ignore 1 lines

举报有用(4分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号