开发者

MySQL syntax: What is this?

My exported SQL file contains the lines below:

/*!40101 SET @OLD_CHAR开发者_开发问答ACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

What do these lines mean, unlike CREATE TABLE and INSERT INTO?


They are variable assignments. The assignments are wrapped in executable comments in such a way that they are executed when MySQL is used and left alone if some other RDBMS is used. Furthermore, the 40101 indicates that the comments are not to be retained in the database i.e. if the lines are executed, they are only executed when the sql file is executed.


This is variable assignments wrapped within conditional comments. The code is executed depending on the version of MySQL in question, see comments


Those special comment always confuse me, after checking the doc https://dev.mysql.com/doc/refman/8.0/en/comments.html

if you add a version number after the ! character, the syntax within the comment is executed only if the MySQL version is greater than or equal to the specified version number. The KEY_BLOCK_SIZE keyword in the following comment is executed only by servers from MySQL 5.1.10 or higher:

CREATE TABLE t1(a INT, KEY (a)) /*!50110 KEY_BLOCK_SIZE=1024 */;

That is not hard to understand. In term of 50110, means 5(major)01(minor)10(revision) = run that in MySQL version >= 5.1.10 or higher


These lines are comment. SQL Comment can start by -- till end of line or can be surrounded by /* ... */

I think that lines are related to the file encoding of your exported sql file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜