解决向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";
相关推荐
qianshang2333 小时前
SQL注入学习总结
网络·数据库·渗透
what丶k3 小时前
深入解析Redis数据持久化:RBD机制原理、实操与生产最佳实践
数据库·redis·缓存
疯狂的喵3 小时前
C++编译期多态实现
开发语言·c++·算法
2301_765703144 小时前
C++中的协程编程
开发语言·c++·算法
m0_748708054 小时前
实时数据压缩库
开发语言·c++·算法
瀚高PG实验室4 小时前
通过数据库日志获取数据库中的慢SQL
数据库·sql·瀚高数据库
Hgfdsaqwr4 小时前
Python在2024年的主要趋势与发展方向
jvm·数据库·python
感谢地心引力4 小时前
安卓、苹果手机无线投屏到Windows
android·windows·ios·智能手机·安卓·苹果·投屏
invicinble4 小时前
对于Mysql深入理解
数据库·mysql
lly2024064 小时前
jQuery Mobile 表格
开发语言