简体   繁体   English

如何在InnoDB表的已安装分区上更改数据目录?

[英]How to change data directory over mounted partition of InnoDB table?

I'm using MariaDB 5.5.44. 我正在使用MariaDB 5.5.44。 I want to create InnoDB table which store data across mounted partition. 我想创建一个InnoDB表,该表跨已安装的分区存储数据。

Consider I had mounted partition /var/log/storage as follow: 考虑我已经按如下方式挂载了分区/ var / log / storage

/dev/sda2       6.5G  3.6G  2.6G  59% /
/dev/sda1       395M   32M  338M   9% /boot
/dev/sda6       5.3G   22M  5.0G   1% /var/log/storage

To create table I use following query: 要创建表,我使用以下查询:

create table InnoDB_Test(a INT) DATA DIRECTORY='/var/log/storage/MySQL' INDEX DIRECTORY='/var/log/storage/MySQL' engine=InnoDB;

But it store data in /var/lib/mysql instead of /var/log/storage/MySQL 但是它将数据存储在/ var / lib / mysql中,而不是/ var / log / storage / MySQL中

Same If I tried with MyISAM using following query & which works as expected: 如果我使用以下查询尝试使用MyISAM,则相同,并且按预期工作:

create table MyISAM_Test(a INT) DATA DIRECTORY='/var/log/storage/MySQL' INDEX DIRECTORY='/var/log/storage/MySQL' engine=MyISAM;

How I can change data directory to mounted partition in InnoDB? 如何在InnoDB中将数据目录更改为已挂载的分区? Why data partition works in MyISAM & not in InnoDB? 为什么数据分区在MyISAM中起作用而在InnoDB中不起作用?

Thank you in advance. 先感谢您。

I wanted to do this (for partitioning) but the mysql documentation says "No". 我想这样做(用于分区),但是mysql文档说“ No”。

Here's the relevant section from this page: https://dev.mysql.com/doc/refman/5.5/en/partitioning-overview.html 这是此页面上的相关部分: https : //dev.mysql.com/doc/refman/5.5/en/partitioning-overview.html

19.1 Overview of Partitioning in MySQL 19.1 MySQL分区概述

The DATA DIRECTORY and INDEX DIRECTORY options have no effect when defining partitions for tables using the InnoDB storage engine. 使用InnoDB存储引擎为表定义分区时,DATA DIRECTORY和INDEX DIRECTORY选项无效。

So it'll work if your storage engine is using MyISAM. 因此,如果您的存储引擎正在使用MyISAM,它将可以正常工作。

Your options are to: 您的选择是:

  1. globally specficy the data directory in mysql command line options or my.cnf file to point to /var/log/storage. 在mysql命令行选项或my.cnf文件中全局指定数据目录以指向/ var / log / storage。 eg --datadir=/var/log/storage 例如--datadir = / var / log / storage
  2. move the whole mysql data dir to /dev/sda6 and mount it to /var/lib/mysql. 将整个mysql数据目录移动到/ dev / sda6并将其安装到/ var / lib / mysql。 This is pretty much the same as the first option, except you get to keep the path /var/lib/mysql 这与第一个选项几乎相同,除了保留路径/ var / lib / mysql
  3. create a tablespace directory for your innodb data and mounting /dev/sda6 to it. 为您的innodb数据创建一个表空间目录,并将/ dev / sda6挂载到该目录。

For the third option, to put innodb data in a seperate directory you configure innodb to create a file per table 对于第三个选项,要将innodb数据放在单独的目录中,请配置innodb以为每个表创建一个文件

# my.cnf
[mysqld]
innodb_file_per_table=1

Once you've rebuilt your db/tables you'll find that a directory (eg /var/lib/mysql/mydb) for your tablespace will get created with individual files for each table. 重建数据库/表后,您会发现将为表空间创建一个目录(例如,/ var / lib / mysql / mydb),并为每个表创建单独的文件。

Then you can copy the tablespace directory and files over to sda6 and mount /dev/sda6 to /var/lib/mysql/mydb 然后,您可以将表空间目录和文件复制到sda6并将/ dev / sda6挂载到/ var / lib / mysql / mydb

Apparently mysql server 5.6 doesn't suffer this limitation. 显然,mysql服务器5.6不受此限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM