欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

source命令执行sql文件报错Failed to open file 'F:_goods-2.sql', error: 2

程序员文章站 2022-05-31 20:15:24
...

今天笔者数据库插入数据时,发生了一个错误。

mysql> source F:\t_goods-2.sql;
Outfile disabled.
ERROR:
Failed to open file 'F:_goods-2.sql', error: 2
mysql>
mysql>

**
大概意思是无法打开t_goods-2.sql这个文件,那么为什么无法打开呢?
笔者这又执行了这样的代码

mysql> source F:\t_goods-2.sql

此时不要分号自接回车,那么控制台会依次执行sql文件中的语句,并在控制台中展现出来
此时笔者发现

ERROR 1366 (HY000): Incorrect string value: '\xAE\xB0\xE4\xBA\x8B\xE6...' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAE\xE9\x9D\xA2\xE6\x97...' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAE\xE9\x9D\xA2\xE6\x97...' for column 'item_type' at row 1
ERROR 1406 (22001): Data too long for column 'item_type' at row 1
ERROR 1406 (22001): Data too long for column 'item_type' at row 1
ERROR 1406 (22001): Data too long for column 'item_type' at row 1
ERROR 1406 (22001): Data too long for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x83 7000' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x83 7000' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x83 7000' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x83 7000' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x83 7000' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x83 7000' for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAE\xB0\xE6\x9C\xAC' for column 'item_type' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAF\xB8\xEF\xBC\x88i...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAF\xB8\xEF\xBC\x88i...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xB0310\xE4\xBD...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xB0310\xE4\xBD...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xB0310\xE7\xBB...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xB0310\xE7\xBB...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xB0310\xE9\xAB...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xB0310\xE9\xAB...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x9B \xE6\xB8\x85\xE6...' for column 'sell_point' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x9B \xE6\xB8\x85\xE6...' for column 'sell_point' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x9B \xE6\xB8\x85\xE6...' for column 'sell_point' at row 1
ERROR 1406 (22001): Data too long for column 'item_type' at row 1
ERROR 1406 (22001): Data too long for column 'item_type' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xA7\x80\xE4\xBA\xA7\xE5...' for column 'sell_point' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xA7\x80\xE4\xBA\xA7\xE5...' for column 'sell_point' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAE\xB6\xE7\x89\x88' for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x88 ' for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x8801CD\xEF...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x8801CD\xEF...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x8801CD\xEF...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x8801CD\xEF...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x8801CD\xEF...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x85 bag\xE9...' for column 'title' at row 1
ERROR 1366 (HY000): Incorrect string value: '\x85 bag\xE7...' for column 'title' at row 1
ERROR 1406 (22001): Data too long for column 'name' at row 1

那么看到了问题的本质,字段长度不够,还有编码问题。那么方法也就有了

解决方法:

**
首先先执行set names gbk;
然后修改’item_type’字段的长度,比以前更长。比如我的是

`item_type` varchar(100) DEFAULT NULL COMMENT '商品系列'

现在修改为

`item_type` varchar(200) DEFAULT NULL COMMENT '商品系列'

随后再看看字符集编码是否正确。
这里建议大家用数据库软件导入sql文件,不要通过命令行导入。
最后再导入sql文件,随后就能成功了。
source命令执行sql文件报错Failed to open file 'F:_goods-2.sql', error: 2此时就发现数据库中有这两张表了。

上一篇: NPM使用入门

下一篇: NPM入门了解