解决向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";
相关推荐
djjdjdjdjjdj3 小时前
如何快速查询SQL中的重复记录:GROUP BY与COUNT统计
jvm·数据库·python
2301_782659183 小时前
Redis怎样监控当前发生了多少次内存驱逐
jvm·数据库·python
万世浮华戏骨3 小时前
PHP 与数据库交互 与 SQL注⼊漏洞
数据库·sql·php
m0_617881423 小时前
如何在新电脑上正确运行已部署的 Django 项目
jvm·数据库·python
u0109147603 小时前
Golang怎么计算日期差天数_Golang如何计算两个日期之间相差多少天【方法】
jvm·数据库·python
蚰蜒螟3 小时前
从 pthread_create 到 thread_native_entry:glibc 如何唤醒 Java 线程
java·开发语言
We་ct3 小时前
LeetCode 300. 最长递增子序列:两种解法从入门到优化
开发语言·前端·javascript·算法·leetcode·typescript
gCode Teacher 格码致知3 小时前
Python提高: unittest和 pytest的使用方法-由Deepseek产生
开发语言·python·pytest
pele3 小时前
Python Tkinter如何实现组件拖拽交换位置_计算鼠标坐标重排布局
jvm·数据库·python
hua872223 小时前
Spring Boot 中使用 @Transactional 注解配置事务管理
数据库·spring boot·sql