Convert to split table

I have the following table structure with live data in it:

 CREATE TABLE IF NOT EXISTS `userstatistics` (
   `user_id` int(10) unsigned NOT NULL,
   `number_logons` int(7) unsigned NOT NULL DEFAULT '0',
   `number_profileminiviews` int(7) unsigned NOT NULL DEFAULT '0',
   `number_profilefullviews` int(7) unsigned NOT NULL DEFAULT '0',
   `number_mailsreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_interestreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_favouratesreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_friendshiprequestreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_imchatrequestreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `yearweek` int(6) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (`user_id`,`yearweek`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I want to convert this to a partitioned table with the following structure:

 CREATE TABLE IF NOT EXISTS `userstatistics` (
   `user_id` int(10) unsigned NOT NULL,
   `number_logons` int(7) unsigned NOT NULL DEFAULT '0',
   `number_profileminiviews` int(7) unsigned NOT NULL DEFAULT '0',
   `number_profilefullviews` int(7) unsigned NOT NULL DEFAULT '0',
   `number_mailsreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_interestreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_favouratesreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_friendshiprequestreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `number_imchatrequestreceived` int(7) unsigned NOT NULL DEFAULT '0',
   `yearweek` int(6) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (`user_id`,`yearweek`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY RANGE (yearweek)
 (PARTITION userstats_201108 VALUES LESS THAN (201108) ENGINE = InnoDB,
  PARTITION userstats_201109 VALUES LESS THAN (201109) ENGINE = InnoDB,
  PARTITION userstats_201110 VALUES LESS THAN (201110) ENGINE = InnoDB,
  PARTITION userstats_201111 VALUES LESS THAN (201111) ENGINE = InnoDB,
  PARTITION userstats_201112 VALUES LESS THAN (201112) ENGINE = InnoDB,
  PARTITION userstats_201113 VALUES LESS THAN (201113) ENGINE = InnoDB,
  PARTITION userstats_201114 VALUES LESS THAN (201114) ENGINE = InnoDB,
  PARTITION userstats_201115 VALUES LESS THAN (201115) ENGINE = InnoDB,
  PARTITION userstats_201116 VALUES LESS THAN (201116) ENGINE = InnoDB,
  PARTITION userstats_201117 VALUES LESS THAN (201117) ENGINE = InnoDB,
  PARTITION userstats_201118 VALUES LESS THAN (201118) ENGINE = InnoDB,
  PARTITION userstats_201119 VALUES LESS THAN (201119) ENGINE = InnoDB,
  PARTITION userstats_201120 VALUES LESS THAN (201120) ENGINE = InnoDB,
  PARTITION userstats_201121 VALUES LESS THAN (201121) ENGINE = InnoDB,
  PARTITION userstats_max VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */;

How can I do this conversion?

Just changing the first line of the second SQL statement to

 ALTER TABLE 'userstatistics' (

Will it do it?

Migrating from MySQL 5.0 to 5.1.

+5
source share
3 answers

First you need to run MySQL 5.1 or later. MySQL 5.0 does not support partitioning.

-, ( ) ( MySQL). . , :

ALTER TABLE 'userstatistics' (

:

ALTER TABLE `userstatistics` (

, , ALTER TABLE. , MySQL 5.1.57:

ALTER TABLE userstatistics PARTITION BY RANGE (yearweek)  (
PARTITION userstats_201108 VALUES LESS THAN (201108) ENGINE = InnoDB,   
PARTITION userstats_201109 VALUES LESS THAN (201109) ENGINE = InnoDB,   
PARTITION userstats_201110 VALUES LESS THAN (201110) ENGINE = InnoDB,   
PARTITION userstats_201111 VALUES LESS THAN (201111) ENGINE = InnoDB,   
PARTITION userstats_201112 VALUES LESS THAN (201112) ENGINE = InnoDB,   
PARTITION userstats_201113 VALUES LESS THAN (201113) ENGINE = InnoDB,   
PARTITION userstats_201114 VALUES LESS THAN (201114) ENGINE = InnoDB,   
PARTITION userstats_201115 VALUES LESS THAN (201115) ENGINE = InnoDB,   
PARTITION userstats_201116 VALUES LESS THAN (201116) ENGINE = InnoDB,   
PARTITION userstats_201117 VALUES LESS THAN (201117) ENGINE = InnoDB,   
PARTITION userstats_201118 VALUES LESS THAN (201118) ENGINE = InnoDB,   
PARTITION userstats_201119 VALUES LESS THAN (201119) ENGINE = InnoDB,   
PARTITION userstats_201120 VALUES LESS THAN (201120) ENGINE = InnoDB,   
PARTITION userstats_201121 VALUES LESS THAN (201121) ENGINE = InnoDB, 
PARTITION userstats_max VALUES LESS THAN MAXVALUE ENGINE = InnoDB);

, , , , . , , , , . , , , .

+5

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html .

, , . ADD/DROP/COALESCE/REORGANIZE sql .

, .

• ALTER TABLE... ADD PARTITION , , NDB. ADD DROP RANGE LIST . ADD COALESCE HASH KEY ; LINEAR HASH LINEAR KEY, , ( ). REORGANIZE .

0

All Articles