我正在使用MySQL Server 5.7,并创建了下表:
CREATE TABLE MYDATA (
hashpart SMALLINT UNSIGNED NOT NULL)
PARTITION BY RANGE COLUMNS(hashpart) (
PARTITION p_123 VALUES LESS THAN(123) DATA DIRECTORY = 'C:\\MyDataBase',
PARTITION p_MAXVALUE VALUES LESS THAN(MAXVALUE) DATA DIRECTORY = 'C:\\Log\\MyDataBase'
);
有没有办法只使用MySQL查询知道每个分区的DATA DIRECTORY的值? 以下查询没有多大帮助:
SELECT * FROM information_schema.partitions WHERE TABLE_NAME = 'MYDATA';
提前感谢您的回答!
答案 0 :(得分:2)
如果您的分区使用InnoDB(查询不适用于其他类型的引擎),您可以运行如下查询(根据需要修改查询):
mysql> DROP TABLE IF EXISTS `MYDATA`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE TABLE IF NOT EXISTS `MYDATA` (
-> `hashpart` SMALLINT UNSIGNED NOT NULL)
-> PARTITION BY RANGE COLUMNS(`hashpart`) (
-> PARTITION `p_123` VALUES LESS THAN(123) DATA DIRECTORY = '/path/to/partition/MyDataBase0',
-> PARTITION `p_MAXVALUE` VALUES LESS THAN(MAXVALUE) DATA DIRECTORY = '/path/to/partition/MyDataBase1'
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT
-> `p`.`PARTITION_NAME`,
-> LEFT(`isdf`.`PATH`, INSTR(`isdf`.`PATH`, `ist`.`NAME`) - 2) `PATH`
-> FROM
-> `information_schema`.`PARTITIONS` `p`
-> INNER JOIN `information_schema`.`INNODB_SYS_TABLESPACES` `ist` ON
-> `ist`.`NAME` LIKE CONCAT(`p`.`TABLE_SCHEMA`, '/', `p`.`TABLE_NAME`, '%', `p`.`PARTITION_NAME`)
-> INNER JOIN `information_schema`.`INNODB_SYS_DATAFILES` `isdf` ON
-> `ist`.`SPACE` = `isdf`.`SPACE`
-> WHERE
-> `TABLE_SCHEMA` = 'test' AND
-> `TABLE_NAME` = 'MYDATA';
+----------------+--------------------------------+
| PARTITION_NAME | PATH |
+----------------+--------------------------------+
| p_123 | /path/to/partition/MyDataBase0 |
| p_MAXVALUE | /path/to/partition/MyDataBase1 |
+----------------+--------------------------------+
2 rows in set (0.01 sec)
请参阅db-fiddle。