Domanda

I've been using mysql for a very long time, but didn't really look into one of its features - directives inside a dump. I'm currently working on partitioning, so let's take it for an example and let's look at code from http://dev.mysql.com/tech-resources/articles/mysql_55_partitioning.html:

show create table t2\G
*************************** 1. row ***************************
       Table: t2
Create Table: CREATE TABLE `t2` (
  `dt` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50500 PARTITION BY RANGE (to_seconds(dt))
(PARTITION p01 VALUES LESS THAN (63426787200) ENGINE = MyISAM,
 PARTITION p02 VALUES LESS THAN (63426816000) ENGINE = MyISAM,
 PARTITION p03 VALUES LESS THAN (63426844800) ENGINE = MyISAM,
 PARTITION p04 VALUES LESS THAN (63426873600) ENGINE = MyISAM,
 PARTITION p05 VALUES LESS THAN (63426902400) ENGINE = MyISAM,
 PARTITION p06 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */

The thing I'm interested in is /*!50500 [...] */. What is it and how it works? I assume it's kind of a directive for mysql when parsing the dump file. As for a directive, I guess it can be switched on or off. That would be cool - I could have a database dump with tables partitioned and - while switching off 50500 directive - I could load the dump without partitioning (it'd be ignored, I guess). Is that possible, how to do that?

È stato utile?

Soluzione

It's neither a mysqldump feature nor a directive code or name. It's good old MySQL conditional comments:

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 TEMPORARY keyword in the following comment is executed only by servers from MySQL 3.23.02 or higher:

CREATE /*!32302 TEMPORARY */ TABLE t (a INT);

The comment syntax just described applies to how the mysqld server parses SQL statements. The mysql client program also performs some parsing of statements before sending them to the server. (It does this to determine statement boundaries within a multiple-statement input line.)

Comments in this format, /*!12345 ... */, are not stored on the server. If this format is used to comment stored routines, the comments will not be retained on the server.

Thus 50500 stands for MySQL 5.5.0 or greater. It's a way to ensure that dumps can get restored in older servers.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top