解决向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";
相关推荐
SelectDB3 小时前
阶跃星辰基于 SelectDB 构建 PB 级 Agent 可观测平台
大数据·数据库·aigc
这个DBA有点耶4 小时前
GROUP BY优化全解:如何写出既不丢数据又飞快的分组查询
数据库·mysql·架构
掉头发的王富贵8 小时前
【StarRocks】极限十分钟入门StarRocks
数据库·sql·mysql
Nturmoils8 小时前
WHERE 条件别凭习惯写,常用查询先跑一遍
数据库
37手游移动客户端团队11 小时前
招聘-高级安卓开发工程师
android·客户端
用户416596736935512 小时前
WebView 请求异常排查操作手册
android·前端
SamDeepThinking12 小时前
一条UPDATE语句在MySQL 8.0中到底加了几把锁?
后端·mysql·程序员
Kapaseker13 小时前
学不动了,入门 Compose Styles API
android·kotlin
Databend1 天前
在 AWS 中国峰会逛了一天,我在 Databend 展台看到了 Agent 数据基础设施的新思路
数据库·人工智能·agent
墨狂之逸才1 天前
Android TV WebView 遥控器按键处理:从全透传到白名单
android