Mysql——》用load data命令把txt导入到Mysql
创始人
2024-03-26 22:20:04
0

一、语法

load data local infile "txt文件路径"
into table 表名 
fields terminated by "," 
lines terminated by "\n"; 
参数描述
load data local infile “txt文件路径”绝对路径(双/单引号包起来)
fields terminated by “,”字段分隔符
lines terminated by “\n”;行分隔符

1、表字段数>txt字段数

表字段id,name,age
txt字段id,name,address,age
load data local infile "c:/Users/xiaox/Desktop/test.txt" 
into table test
fields terminated by ","
lines terminated by "\n" 
(id,name,@abc,age);

@abc表示变量,使用变量作为占位符,导入时等于丢掉这列数据。

2、表字段数
表字段id,name,age
txt字段name,age
load data local infile "c:/Users/xiaox/Desktop/test.txt" 
into table test
fields terminated by ","
lines terminated by "\n" 
(name,age);

二、示例

C:\Users\xiaox>mysql -h localhost -u root -p xiaoxian --local-infile
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.26 MySQL Community Server - GPLCopyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> load data local infile "c:/Users/xiaox/Desktop/test.txt" into table test (id,area);
Query OK, 2 rows affected, 4 warnings (0.01 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 4mysql> load data local infile "c:/Users/xiaox/Desktop/test.txt" into table test fields terminated by ",";
Query OK, 0 rows affected, 2 warnings (0.01 sec)
Records: 2  Deleted: 0  Skipped: 2  Warnings: 2mysql> load data local infile "c:/Users/xiaox/Desktop/test.txt" into table test fields terminated by "," (area,id);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 0

三、错误

1、ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

解决——》ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

2、ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides

解决——》ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides

3、ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.

解决——》ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...