当前位置:网站首页>. SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */

. SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */

2022-06-25 23:09:00 KFC home delivery specialist

Error phenomenon

adopt navicat Import sql File failed .

Screenshot of error reporting

Troubleshooting of error reporting reasons

1. First, check whether it is due to sql The file contains a large number of comments

      I began to think it was through mysqldump Command export database , Exported sql There is a lot of annotation information in the Chinese back . Unrecognized when importing , Later, I searched the meaning of the notes and found that it didn't seem to be .

1) Meaning of notes /*! Back number , In fact, that is mysql Version number information , When the version number is higher than or equal to the version number in the comment , Inside set Orders will be executed .

for example :/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;

1)40101, This is a mysql Version number , This number tells us that these statements are only available if they are greater than or equal to the version mysql In order to execute , That is to say mysql4.01.01 And above mysql In the implementation of

2)set Statement is to set the current system variable CHARACTER_SET_CLIENT The value is assigned to OLD_CHARACTER_SET_CLIENT

2) Prohibit... While importing data / Activate index

explain :

         DISABLE KEYS It is forbidden to index

         ENABLE KEYS Is to activate the index

          When inserting data , The index will be disabled first , Reactivate the index , This saves time importing data

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) The following comment statement appears at the end of the backup file , Use set To restore the original value of the server system variable :

/*!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 */;

Reference resources blog:

MySQL Annotation form _ Executable comment statements (/*!...*/)_ Database comments _ Database script comments _SQL Script comment format _SQL Script comment classification _liaowenxiong The blog of -CSDN Blog _mysql Script comment Why should the article directory be executable SQL The statement is written in the comment ? Comment example other comment statements /*!...*/ This is called an executable comment (executable comments), The statement in the comment will be MySQL Normal parsing and execution , But in other DBMS it will be ignored as a comment , This can improve the portability of database scripts . Why put executable SQL The statement is written in the comment ?MySQL Contains some other DBMS Function extensions not available in , If you use them , Will not be able to migrate code to other DBMS in . In some cases , You can write something that contains MySQL Code for special extension functions , But it still keeps its https://blog.csdn.net/liaowenxiong/article/details/117223010   Use sed Command deletion SQL Comment information in the file When we need to migrate databases , And the data is from the lower version mysql Migrate to a higher version of mysql Use , Use mysqldump Command export database , Exported SQL There will be a lot of annotation information in , as follows : / !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 @OLDhttps://copyfuture.com/blogs-details/20200325114105956muk0wbvlten06s4

2. screening mysql edition

adopt select version() Inquire about MySQL Version of , Found version is 5.6.51, It is greater than 4.01.01 The version of the , Should support

3. navicat Do you support mysqldump Derived sql file

Then I intercepted a paragraph containing comments sql The file goes straight to navicat To perform , It is found that annotations can run through , however mysql Statement error , Vomit and shout to solve the case , therefore navicat Is to support the , yes sql There is a problem in the statement

 4. mysql Statement troubleshooting

newspaper Unknown collation: 'utf8mb4_0900_ai_ci' So I passed show charset Check the currently supported character set and the corresponding sorting rules , Can't find utf8mb4 Only found utf8 Character set , Should not support utf8mb4 Character type

Then I went to check  CHARSET=utf8mb4 and CHARSET=utf8mb4 The difference between :

utf8 The encoding method indicates that a character needs 1-4 Bytes , But common characters only need 1-3 It's just a byte ; And in the MySQL The maximum byte length used to represent a character in will affect the storage and performance of the system , therefore utf8 It's actually utf8mb3, The box 1-3 The encoding method of byte encoding ;

If there are some special characters in the data ( Such as emoji expression ) Then please use utf8mb4.
 

solve the problem

Replace the character set in the character set and collation with utf8 Replace the collation with utf8_general_ci

  Reference resources blog:

MySQL Database import SQL Report errors Unknown collation: ‘utf8mb4_0900_ai_ci‘ Solutions for _ Xiao Liu should work hard (ง •̀_•́)ง The blog of -CSDN Blog _mysql utf8mb4_0900_ai_ciMySQL Database import SQL Report errors Unknown collation: ‘utf8mb4_0900_ai_ci‘ The reason for the error : I'm a local MySQL The package version is 8.0 Of , And on the server MySQL Version is 5.7, Both versions are incompatible , This led me to write it locally SQL Unable to on the server MySQL Up operation . terms of settlement : Scheme 1 : Put the MySQL Upgrade to higher version scheme 2 : Will need to import SQL The character set in the file consists of utf8mb4 Replace with utf8, Collation by utf8...https://blog.csdn.net/weixin_44684272/article/details/119821853

Summary of experience

1. Next time if sql Still can't lead in , You can post a paragraph directly sql Go to the connection query to read the error report , Then row , It can save time and locate the problem more quickly

2. After the replacement, search the keyword globally to see if there is any omission

2022/06/25

原网站

版权声明
本文为[KFC home delivery specialist]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251926549713.html