解决向MySQL中导入文件中的 数据时出现的问题~

SQL语句如下所示:

sql 复制代码
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/data1.txt'
into table user
fields terminated by ',' 
lines terminated by "\n"
(name,sex,age,address,email,id,phone);

报错1:

The MySQL server is running with the --secure-file-priv option so it

cannot execute this statement

错误1解决办法:

第一步:我们找到MySQL中的my.ini文件,向该文件中加入如下代码

sql 复制代码
[mysqld]
#Secure File Priv.
secure-file-priv=""

第二步:打开任务资源管理器,重启MySQL服务

报错2:

Invalid utf8mb3 character string:"

这是由于我们当前数据库的字符编码和我们文本文件中的不一致导致的

解决办法:

sql 复制代码
ALTER database wjr DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

其他需要注意的问题:

sql 复制代码
-- 第一(name,sex,age,address,email,id,phone)可以不写这行代码
-- 字段值之间使用英文逗号分割而不是中文
fields terminated by ',' 
-- 行与行之间使用换行符相隔
lines terminated by "\n";
相关推荐
NiceCloud喜云5 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
ccddsdsdfsdf5 小时前
DBeaver怎么链接mongoDB
数据库·mongodb
AI玫瑰助手6 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
油炸自行车6 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋6 小时前
C++14特性
开发语言·c++·c++14特性
丷丩6 小时前
Postgresql基础实践教程(十一)各种Join
数据库·postgresql·join
星夜夏空996 小时前
FreeRTOS学习(4)——内存映射
数据库·学习·mongodb
TheRouter7 小时前
AI Agent 记忆体系建设实战:短期、长期与工作记忆的工程实现
数据库·人工智能·oracle
Omics Pro7 小时前
首个!外源天然产物综合性代谢图谱
数据库·人工智能·算法·机器学习·r语言
JAVA社区7 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展