当前位置:网站首页>.sql数据库导入错误:/*!40101 SET @[email protected]@COLLATION_CONNECTION */
.sql数据库导入错误:/*!40101 SET @[email protected]@COLLATION_CONNECTION */
2022-06-25 21:50:00 【KFC宅急送专员】
错误现象
通过navicat导入sql文件失败。
报错截图


报错原因排查
1. 首先排查了是不是由于sql文件中包含了大量注释导致的
我开始以为是通过mysqldump命令导出数据库,所导出的sql中回包含许多的注释信息。导入的时候无法识别,后来去搜了注释的含义发现好像并不是。
1)注释的含义/*!后面的数字,其实就是mysql版本号信息,意思是当版本号高于或者等于注释里的版本号时,里面的set命令才会被执行。
例如:/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
1)40101,这是mysql版本号,该数字告诉我们这些语句只有在大于或等于该版本的mysql中才能执行,即在mysql4.01.01及以上版本的mysql中执行
2)set 语句是将当前系统变量CHARACTER_SET_CLIENT的值赋给OLD_CHARACTER_SET_CLIENT
2)导入数据时禁止/激活索引
说明:
DISABLE KEYS 是禁止索引
ENABLE KEYS 是激活索引
在插入数据时,都会先禁止索引,再激活索引,这样可以节省导入数据的时间
LOCK TABLES `tb_shop_order` WRITE;
/*!40000 ALTER TABLE `tb_shop_order` DISABLE KEYS */;
INSERT INTO `tb_shop_order` VALUES (1,1,1,1,1.000000,1.000000,'1','1','1',1,'1','2020-02-20 00:00:00',1,'2020-02-20 00:00:00',1,'2020-02-20 00:00:00','1')
/*!40000 ALTER TABLE `tb_shop_order` ENABLE KEYS */
3)在备份文件末尾会出现如下注释语句,使用set的语句恢复服务器系统变量原来的值:
/*!40103 SET [email protected]_TIME_ZONE */;
/*!40101 SET [email protected]_SQL_MODE */;
/*!40014 SET [email protected]_FOREIGN_KEY_CHECKS */;
/*!40014 SET [email protected]_UNIQUE_CHECKS */;
/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;
/*!40101 SET [email protected]_COLLATION_CONNECTION */;
/*!40111 SET [email protected]_SQL_NOTES */;
参考blog:
MySQL注释形式_可执行注释语句(/*!...*/)_数据库注释_数据库脚本注释_SQL脚本注释格式_SQL脚本注释分类_liaowenxiong的博客-CSDN博客_mysql 脚本注释文章目录为什么要把可执行的 SQL 语句写在注释里面呢?注释示例其它注释语句/*!...*/ 这叫可执行的注释(executable comments),注释当中的语句会被 MySQL 正常解析和执行,但在其他数据库管理系统将被作为注释忽略,这可以提高数据库脚本的可移植性。为什么要把可执行的 SQL 语句写在注释里面呢?MySQL 包含一些其它 DBMS 中不具备的功能扩展,如果使用了它们,将无法把代码移植到其它 DBMS 中。在某些情况下,你可以编写包含 MySQL 特殊扩展功能的代码,但仍保持其可https://blog.csdn.net/liaowenxiong/article/details/117223010 使用sed命令删除SQL文件中的注释信息当我们需要进行数据库迁移,而数据又是从低版本的mysql迁移到高版本的mysql使用,使用mysqldump命令导出数据库,所导出的SQL中会有许多的注释信息,如下: / !40101 SET @[email protected]@CHARACTER_SET_CLIENT /; / !40101 SET @[email protected]@CHARACTER_SET_RESULTS /; / !40101 SET @[email protected]@COLLATION_CONNECTION /; / !40101 SET NAMES utf8 /; / !40103 SET @[email protected]@TIME_ZONE /; / !40103 SET TIME_ZONE='+00:00' /; / !40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /; / !40014 SET @OLD
https://copyfuture.com/blogs-details/20200325114105956muk0wbvlten06s4
2. 排查mysql版本
通过select version()查询MySQL的版本,发现版本为5.6.51,是大于4.01.01的版本的,理应支持

3. navicat是否支持mysqldump导出的sql文件
然后我就截取了一段包含注释的sql文件直接放navicat中去执行,发现注释是能跑通的,但是mysql语句报错了,呕吼破案,所以navicat是支持的,是sql语句中有问题

4. mysql语句排查
报Unknown collation: 'utf8mb4_0900_ai_ci'的错于是我通过show charset查了一下当前支持的字符集和对应的排序规则,没有找到utf8mb4只找到了utf8字符集,应当是不支持utf8mb4字符类型
然后去查了 CHARSET=utf8mb4 和CHARSET=utf8mb4的区别:
utf8编码方式表示一个字符需要1-4个字节,但常用的字符只需1-3个字节就可以表示了;而在MySQL中表示一个字符所用的最大字节长度会影响系统的存储和性能,所以utf8指的其实是utf8mb3,即用1-3个字节编码的编码方式;
如果数据中有一些特殊字符(如emoji表情)那么请使用utf8mb4。

解决问题
把字符集和排序规则中的字符集替换成utf8排序规则替换成utf8_general_ci

参考blog:
经验总结
1.下一次如果sql还是导不进去,可以直接贴一段sql到连接查询里去执行看报错,然后再排,可以节约时间更快速的定位到问题
2. 替换完了最后全局搜一下关键字看有没有遗漏
2022/06/25
边栏推荐
- Open source optimized VVC encoder in general scenarios
- CVPR2022教程 | 马里兰大学《机器学习遥感处理:农业与粮食安全》教程
- HotSpot JVM 「01」类加载、链接和初始化
- 华为云短信测了很多手机都提示发送频繁
- Market depth analysis and development strategy consulting report of China's fire equipment market 2022-2028
- Yyds dry goods inventory JD 2, why is redis so fast?
- What should it personnel over 35 years old do if they are laid off by the company one day?
- 2022-2028 global open source cloud storage industry research and trend analysis report
- China bed and mattress market status research analysis and development prospect forecast report (2022)
- Chapter 3 use of requests Library
猜你喜欢

2022-2028 global horizontal reciprocating compressor industry research and trend analysis report

哪些PHP开源作品值得关注

2022-2028 global web and browser isolation platform industry research and trend analysis report

Data governance is easier said than done

ES6-Const常量与数组解构

聊聊Adapter模式

面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?

Relinearization in homomorphic encryption (ckks)

ES7/ES9 -- 新特性与正则

2022-2028 global proton exchange membrane hydrogen electrolyzer industry survey and trend analysis report
随机推荐
2022-2028 global TFT touch screen industry research and trend analysis report
Analysis report on market demand situation and investment direction of China's optical transmission equipment industry from 2022 to 2028
Huawei cloud SMS has tested that many mobile phones prompt frequent sending
MySQL数据库索引
Cvpr2022 tutorial | machine learning remote sensing processing: agriculture and food security, University of Maryland
Analysis report on scale investigation and investment development suggestions of China's special equipment inspection and testing industry 2022-2028
Online crudhasone Association query reports an error unabletouseinternalvariable:list
How to guarantee idempotency of message queue
C language and the creation and use of database
记|一次exists关键字的学习记录
What are the channels for Internet advertising to gain customers?
Global and Chinese flame retardant ABS industry development trend and market demand analysis report 2022 ~ 2028
2022giao考游记
2022-2028 global open source cloud storage industry research and trend analysis report
Some reflections on preparing for the Blue Bridge Cup
Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
2022-2028 global SiC igniter industry research and trend analysis report
Open source optimized VVC encoder in general scenarios
你好,请问老师,在支付宝基金开户真的安全吗?
A3.ansible production practice case -- system initialization roles