在MySQL中分区数据库表 [英] Partitioning a database table in MySQL

查看:220
本文介绍了在MySQL中分区数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MySQL 作为后端编写数据仓库。我需要根据两个整数ID和一个名称字符串对表进行分区。

I am writing a data warehouse, using MySQL as the back-end. I need to partition a table based on two integer IDs and a name string.

一个更具体的例子是假设我正在存储有关学校的数据。我想根据以下的COMPOSITE'Key'分区school_data表:

A more concrete example would be to assume that I am storing data about a school. I want to partition the school_data table based on COMPOSITE 'Key' based on the following:

school id (integer)
course_id (integer)
student_surname (string)

对于学生姓氏,只是姓氏的第一个字符确定数据应该进入哪个分区表。

For the student surname, it is just the first character of the surname that determines which 'partitioned table' the data should go in to.

如何使用MySQL(5.1)与InnoDb表实现此要求?

How may I implement this requirement using MySQL (5.1) with InnoDb tables?

此外,我正在Windows框上进行开发,但是我将部署到* nix框上进行生产。我还有另外两个问题:

Also, I am doing my development on a Windows box, but I will deploy onto a *nix box for production. I have two further questions:


  1. 我假设在从Windows迁移到Linux时,我必须转储和恢复数据。我不知道如果数据库包含分区表(指向文档中说明的那个)将放置我的头脑 - 我没有能够找到关于分区表的转储/恢复的任何具体提及,这是否可行。

  2. 我可能还需要更改数据库(如果Oracle在MySQL用户上引发了惊喜),在这种情况下,我将需要将数据导出到另一个数据库中。 ) - 考虑到分区表,将数据从MySQL中转出(也许是文本或某事)的最佳方法是什么?


推荐答案

RANGE分区



按范围划分的表被分区,每个分区包含分区的行表达式值在给定范围内。

RANGE Partitioning

A table that is partitioned by range is partitioned in such a way that each partition contains rows for which the partitioning expression value lies within a given range.

CREATE TABLE employees (
  school id (integer)
  course_id (integer)
  student_surname (string)
)
  PARTITION BY RANGE (student_surname) (
  PARTITION p0 VALUES LESS THAN ('ezzzzzzzzzzzzzzzzzzzzzzz'),
  PARTITION p1 VALUES LESS THAN ('ozzzzzzzzzzzzzzzzzzzzzzz'),
  PARTITION p2 VALUES LESS THAN ('tzzzzzzzzzzzzzzzzzzzzzzz'),
  PARTITION p3 VALUES LESS THAN (MAXVALUE)
);

范围分区

MySQLDUMP将把表和数据输出到一个文件中。但是,Oracle 支持通过ODBC连接到其他数据库,就像SQL Server具有链接服务器功能一样。

MySQLDUMP will output the table and data to a file. However, Oracle supports connecting to other databases via ODBC, just as SQL Server has it's linked server capability.


看起来你只是通过我提到的3个字段之一进行分区(即名称)。我看到了MySQL文档中的单个字段的分区,但是没有像我想要的那样的3个字段(int,int,string)。

It looks like you are partitioning by only one of the 3 fields I mentioned (i.e. name). I saw partitioning by a single field in the MySQL docs, but not 3 fields (int, int, string) like I want to do.

可以通过三列进行分区,但是我的例子是根据OP中的要求:

Partitioning by three columns is possible, but my example is per your requirements in the OP:


对于学生姓氏,它只是姓氏的第一个字符确定数据应该进入哪个分区表。

For the student surname, it just the first character of the surname that determines which 'partitioned table' the data should go in to.

这篇关于在MySQL中分区数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆