/*!40101的含义

本文探讨了MySQL数据库导出脚本中出现的Executable Comments现象,解释了为何在注释中嵌入SQL命令,如/*!40101 SET NAMES utf8 */;,以及这些命令在跨数据库迁移时的作用。文章还详细说明了40101所代表的MySQL版本要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

导出mysql数据表结构,开头会出现一些这样的
 

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

这种写法是executable comments,也就是说里面的变量赋值语句是会被执行的。

为什么要把命令写在注释里面呢? 因为你的导出脚本有些时候可能会拿到其他数据库上去执行。

40101,是指在MySQL 4.1.1(4.01.01)及以上版本上执行。

参考

[导出的mysql中 /*!40101 SET @OLD_CHARACTER_SET_CLIENT... 用途](https://segmentfault.com/q/1010000003781363)

[root@hadoop01 hive]# bin/schematool -dbType mysql -initSchema -verbose SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/programs/apache-hive-2.3.9-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/programs/hadoop-2.7.6/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Metastore connection URL: jdbc:mysql://hadoop01:3306/hive?useSSL=false Metastore Connection Driver : com.mysql.jdbc.Driver Metastore connection User: root Starting metastore schema initialization to 2.3.0 Initialization script hive-schema-2.3.0.mysql.sql Connecting to jdbc:mysql://hadoop01:3306/hive?useSSL=false Connected to: MySQL (version 8.0.42) Driver: MySQL Connector Java (version mysql-connector-java-5.1.48 ( Revision: 29734982609c32d3ab7e5cac2e6acee69ff6b4aa )) Transaction isolation: TRANSACTION_READ_COMMITTED 0: jdbc:mysql://hadoop01:3306/hive> !autocommit on Autocommit status: true 0: jdbc:mysql://hadoop01:3306/hive> /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */ No rows affected (0.004 seconds) 0: jdbc:mysql://hadoop01:3306/hive> /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */ No rows affected (0 seconds) 0: jdbc:mysql://hadoop01:3306/hive> /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */ No rows affected (0 seconds) 0: jdbc:mysql://hadoop01:3306/hive> /*!40101 SET NAMES utf8 */ No rows affected (0.003 seconds) 0: jdbc:mysql://hadoop01:3306/hive> /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */ No rows affected (0.002 seconds) 0: jdbc:mysql://hadoop01:3306/hive> /*!40103 SET TIME_ZONE='+00:00' */ No rows affected (0.001 seconds) 0: jdbc:mysql://hadoop01:3306/hive> /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=
最新发布
07-04
解读以下代码,生成对应表结构:DROP TABLE IF EXISTS `detections`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `detections` ( `id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `image_path` varchar(255) NOT NULL, `license_plate_number` varchar(20) DEFAULT NULL, `confidence` float DEFAULT NULL, `created_at` datetime DEFAULT NULL, `result_image_path` varchar(255) DEFAULT NULL, `detection_metadata` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `ix_detections_license_plate_number` (`license_plate_number`), KEY `ix_detections_id` (`id`), CONSTRAINT `detections_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2288 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `users` -- DROP TABLE IF EXISTS `users`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `users` ( `id` int NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `hashed_password` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, `is_active` tinyint(1) DEFAULT NULL, `is_admin` tinyint(1) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `ix_users_username` (`username`), UNIQUE KEY `ix_users_email` (`email`), KEY `ix_users_id` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
05-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值