您好,登錄后才能下訂單哦!
1.接著用上篇文章中建好的空分區表
2.從未分區表中向分區表中灌數據
mysql> insert into ar_detail_part select * from ar_detail;
Query OK, 103606 rows affected (8.56 sec)
Records: 103606 Duplicates: 0 Warnings: 0
3.查看該表的表空間文件
4.計劃采取兩種辦法:
1~直接復制2014-2016的表空間文件到新的實例中--分區表空間傳輸
1.在新實例中創建相同的庫:
創建相同模式的空表:
mysql --login-path=3306 <ar_detail_part_schema.sql
CREATE TABLE `ar_detail_part` (
`Auto_ID` int(11) NOT NULL,
`iPeriod` tinyint(4) NOT NULL,
`cVouchType` varchar(10) DEFAULT NULL,
`cVouchSType` varchar(2) DEFAULT NULL,
`cVouchID` varchar(30) NOT NULL,
`dVouchDate` datetime NOT NULL,
`dRegDate` datetime NOT NULL,
`cDwCode` varchar(20) NOT NULL,
`cDeptCode` varchar(12) DEFAULT NULL,
`cPerson` varchar(20) DEFAULT NULL,
`cInvCode` varchar(60) DEFAULT NULL,
`iBVid` int(11) DEFAULT NULL,
`cCode` varchar(40) DEFAULT NULL,
`cItem_Class` varchar(2) DEFAULT NULL,
`cItemCode` varchar(60) DEFAULT NULL,
`csign` varchar(2) DEFAULT NULL,
`isignseq` tinyint(4) DEFAULT NULL,
`ino_id` smallint(6) DEFAULT NULL,
`cDigest` varchar(255) DEFAULT NULL,
`iPrice` double DEFAULT NULL,
`cexch_name` varchar(8) NOT NULL,
`iExchRate` double DEFAULT NULL,
`iDAmount` decimal(19,4) DEFAULT NULL,
`iCAmount` decimal(19,4) DEFAULT NULL,
`iDAmount_f` decimal(19,4) DEFAULT NULL,
`iCAmount_f` decimal(19,4) DEFAULT NULL,
`iDAmount_s` double DEFAULT NULL,
`iCAmount_s` double DEFAULT NULL,
`cOrderNo` varchar(30) DEFAULT NULL,
`cSSCode` varchar(3) DEFAULT NULL,
`cPayCode` varchar(3) DEFAULT NULL,
`cProcStyle` varchar(10) DEFAULT NULL,
`cCancelNo` varchar(40) DEFAULT NULL,
`cPZid` varchar(30) DEFAULT NULL,
`bPrePay` tinyint(4) DEFAULT NULL,
`iFlag` tinyint(4) DEFAULT NULL,
`cCoVouchType` varchar(10) DEFAULT NULL,
`cCoVouchID` varchar(30) DEFAULT NULL,
`cFlag` varchar(2) NOT NULL,
`cDefine1` varchar(20) DEFAULT NULL,
`cDefine2` varchar(20) DEFAULT NULL,
`cDefine3` varchar(20) DEFAULT NULL,
`cDefine4` datetime DEFAULT NULL,
`cDefine5` int(11) DEFAULT NULL,
`cDefine6` datetime DEFAULT NULL,
`cDefine7` double DEFAULT NULL,
`cDefine8` varchar(4) DEFAULT NULL,
`cDefine9` varchar(8) DEFAULT NULL,
`cDefine10` varchar(60) DEFAULT NULL,
`iClosesID` int(11) NOT NULL,
`iCoClosesID` int(11) NOT NULL,
`cDefine11` varchar(120) DEFAULT NULL,
`cDefine12` varchar(120) DEFAULT NULL,
`cDefine13` varchar(120) DEFAULT NULL,
`cDefine14` varchar(120) DEFAULT NULL,
`cDefine15` int(11) DEFAULT NULL,
`cDefine16` double DEFAULT NULL,
`cGLSign` varchar(8) DEFAULT NULL,
`iGLno_id` smallint(6) DEFAULT NULL,
`dPZDate` datetime DEFAULT NULL,
`cItemName` varchar(255) DEFAULT NULL,
`cContractType` varchar(10) DEFAULT NULL,
`cContractID` varchar(64) DEFAULT NULL,
`BalancesGuid` char(36) DEFAULT NULL,
`dHideDate` datetime DEFAULT NULL,
`cGatheringPlan` varchar(10) DEFAULT NULL,
`dCreditStart` datetime DEFAULT NULL,
`iCreditPeriod` int(11) DEFAULT NULL,
`dGatheringDate` datetime DEFAULT NULL,
`bCredit` tinyint(4) DEFAULT NULL,
`cOperator` varchar(20) DEFAULT NULL,
`cCheckMan` varchar(20) DEFAULT NULL,
`iOrderType` tinyint(4) DEFAULT NULL,
`cDLCode` varchar(30) DEFAULT NULL,
`idlsid` int(11) DEFAULT NULL,
`copcode` varchar(20) DEFAULT NULL,
`dVouDate` datetime DEFAULT NULL,
`cDefine22` varchar(60) DEFAULT NULL,
`cDefine23` varchar(60) DEFAULT NULL,
`cDefine24` varchar(60) DEFAULT NULL,
`cDefine25` varchar(60) DEFAULT NULL,
`cDefine26` double DEFAULT NULL,
`cDefine27` double DEFAULT NULL,
`cDefine28` varchar(120) DEFAULT NULL,
`cDefine29` varchar(120) DEFAULT NULL,
`cDefine30` varchar(120) DEFAULT NULL,
`cDefine31` varchar(120) DEFAULT NULL,
`cDefine32` varchar(120) DEFAULT NULL,
`cDefine33` varchar(120) DEFAULT NULL,
`cDefine34` int(11) DEFAULT NULL,
`cDefine35` int(11) DEFAULT NULL,
`cDefine36` datetime DEFAULT NULL,
`cDefine37` datetime DEFAULT NULL,
`iAmount` decimal(19,4) DEFAULT NULL,
`iAmount_f` decimal(19,4) DEFAULT NULL,
`iAmount_s` double DEFAULT NULL,
`iVouchAmount` decimal(19,4) DEFAULT NULL,
`iVouchAmount_f` decimal(19,4) DEFAULT NULL,
`iVouchAmount_s` double DEFAULT NULL,
`dtZbjEndDate` datetime DEFAULT NULL,
`cExecID` varchar(30) DEFAULT NULL,
`cBusType` varchar(8) DEFAULT NULL,
PRIMARY KEY (`Auto_ID`,`dVouchDate`),
KEY `Ar_Detail_ibvid_ind` (`iBVid`),
KEY `Ar_Detail_iflag_ind` (`iFlag`),
KEY `Ar_Detail_SY` (`cProcStyle`,`cexch_name`,`cFlag`),
KEY `Ar_cPZID` (`cPZid`),
KEY `Ar_iClosesID` (`iClosesID`),
KEY `Ar_iCoClosesID` (`iCoClosesID`),
KEY `idx_Operator_Ar_Detail` (`cOperator`),
KEY `INDEX_Ar_Detail_cCoVouchID` (`cCoVouchType`,`cCoVouchID`),
KEY `INDEX_Ar_Detail_cVouchID` (`cVouchType`,`cVouchID`),
KEY `INDEX_Ar_Detail_HX` (`cDwCode`,`cexch_name`,`cCoVouchType`),
KEY `INDEX_Ar_Detail_HXZD` (`cProcStyle`,`cCancelNo`,`cFlag`),
KEY `IX_ar_detail_Mx_MIX1` (`cFlag`,`iFlag`,`cDwCode`,`dCreditStart`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
partition by range columns (dvouchdate) (partition p2004 values less than ('2005-01-01 00:00:00.000'),
partition p2005 values less than ('2006-01-01 00:00:00.000'),
partition p2006 values less than ('2007-01-01 00:00:00.000'),
partition p2007 values less than ('2008-01-01 00:00:00.000'),
partition p2008 values less than ('2009-01-01 00:00:00.000'),
partition p2009 values less than ('2010-01-01 00:00:00.000'),
partition p2010 values less than ('2011-01-01 00:00:00.000'),
partition p2011 values less than ('2012-01-01 00:00:00.000'),
partition p2012 values less than ('2013-01-01 00:00:00.000'),
partition p2013 values less than ('2014-01-01 00:00:00.000'),
partition p2014 values less than ('2015-01-01 00:00:00.000'),
partition p2015 values less than ('2016-01-01 00:00:00.000'),
partition p2016 values less than ('2017-01-01 00:00:00.000')
);
刪除表空間
alter table ar_detail_part discard table space;
2.在源表上:
鎖表用于復制表空間
flush tables ar_detail_part for export
復制出來
3.復制到目標庫上
更改文件的權限為mysql.mysql用戶所有
[root@localhost ufdata_min]# chown mysql.mysql ar*
4.引入表空間
alter table ar_detail_part import tablespace;
5.嘗試查看表
mysql> select * from ar_detail_part
-> ;mysql> select count(1) from ar_detail_part;
+----------+
| count(1) |
+----------+
| 103606 |
+----------+
1 row in set (0.82 sec)
2~分區交換(交換后,互相剪切,不推薦)1.在新實例中創建同樣結構的一張表
CREATE TABLE `ar_detail_part_year` (
`Auto_ID` int(11) NOT NULL,
`iPeriod` tinyint(4) NOT NULL,
`cVouchType` varchar(10) DEFAULT NULL,
`cVouchSType` varchar(2) DEFAULT NULL,
`cVouchID` varchar(30) NOT NULL,
`dVouchDate` datetime NOT NULL,
`dRegDate` datetime NOT NULL,
`cDwCode` varchar(20) NOT NULL,
`cDeptCode` varchar(12) DEFAULT NULL,
`cPerson` varchar(20) DEFAULT NULL,
`cInvCode` varchar(60) DEFAULT NULL,
`iBVid` int(11) DEFAULT NULL,
`cCode` varchar(40) DEFAULT NULL,
`cItem_Class` varchar(2) DEFAULT NULL,
`cItemCode` varchar(60) DEFAULT NULL,
`csign` varchar(2) DEFAULT NULL,
`isignseq` tinyint(4) DEFAULT NULL,
`ino_id` smallint(6) DEFAULT NULL,
`cDigest` varchar(255) DEFAULT NULL,
`iPrice` double DEFAULT NULL,
`cexch_name` varchar(8) NOT NULL,
`iExchRate` double DEFAULT NULL,
`iDAmount` decimal(19,4) DEFAULT NULL,
`iCAmount` decimal(19,4) DEFAULT NULL,
`iDAmount_f` decimal(19,4) DEFAULT NULL,
`iCAmount_f` decimal(19,4) DEFAULT NULL,
`iDAmount_s` double DEFAULT NULL,
`iCAmount_s` double DEFAULT NULL,
`cOrderNo` varchar(30) DEFAULT NULL,
`cSSCode` varchar(3) DEFAULT NULL,
`cPayCode` varchar(3) DEFAULT NULL,
`cProcStyle` varchar(10) DEFAULT NULL,
`cCancelNo` varchar(40) DEFAULT NULL,
`cPZid` varchar(30) DEFAULT NULL,
`bPrePay` tinyint(4) DEFAULT NULL,
`iFlag` tinyint(4) DEFAULT NULL,
`cCoVouchType` varchar(10) DEFAULT NULL,
`cCoVouchID` varchar(30) DEFAULT NULL,
`cFlag` varchar(2) NOT NULL,
`cDefine1` varchar(20) DEFAULT NULL,
`cDefine2` varchar(20) DEFAULT NULL,
`cDefine3` varchar(20) DEFAULT NULL,
`cDefine4` datetime DEFAULT NULL,
`cDefine5` int(11) DEFAULT NULL,
`cDefine6` datetime DEFAULT NULL,
`cDefine7` double DEFAULT NULL,
`cDefine8` varchar(4) DEFAULT NULL,
`cDefine9` varchar(8) DEFAULT NULL,
`cDefine10` varchar(60) DEFAULT NULL,
`iClosesID` int(11) NOT NULL,
`iCoClosesID` int(11) NOT NULL,
`cDefine11` varchar(120) DEFAULT NULL,
`cDefine12` varchar(120) DEFAULT NULL,
`cDefine13` varchar(120) DEFAULT NULL,
`cDefine14` varchar(120) DEFAULT NULL,
`cDefine15` int(11) DEFAULT NULL,
`cDefine16` double DEFAULT NULL,
`cGLSign` varchar(8) DEFAULT NULL,
`iGLno_id` smallint(6) DEFAULT NULL,
`dPZDate` datetime DEFAULT NULL,
`cItemName` varchar(255) DEFAULT NULL,
`cContractType` varchar(10) DEFAULT NULL,
`cContractID` varchar(64) DEFAULT NULL,
`BalancesGuid` char(36) DEFAULT NULL,
`dHideDate` datetime DEFAULT NULL,
`cGatheringPlan` varchar(10) DEFAULT NULL,
`dCreditStart` datetime DEFAULT NULL,
`iCreditPeriod` int(11) DEFAULT NULL,
`dGatheringDate` datetime DEFAULT NULL,
`bCredit` tinyint(4) DEFAULT NULL,
`cOperator` varchar(20) DEFAULT NULL,
`cCheckMan` varchar(20) DEFAULT NULL,
`iOrderType` tinyint(4) DEFAULT NULL,
`cDLCode` varchar(30) DEFAULT NULL,
`idlsid` int(11) DEFAULT NULL,
`copcode` varchar(20) DEFAULT NULL,
`dVouDate` datetime DEFAULT NULL,
`cDefine22` varchar(60) DEFAULT NULL,
`cDefine23` varchar(60) DEFAULT NULL,
`cDefine24` varchar(60) DEFAULT NULL,
`cDefine25` varchar(60) DEFAULT NULL,
`cDefine26` double DEFAULT NULL,
`cDefine27` double DEFAULT NULL,
`cDefine28` varchar(120) DEFAULT NULL,
`cDefine29` varchar(120) DEFAULT NULL,
`cDefine30` varchar(120) DEFAULT NULL,
`cDefine31` varchar(120) DEFAULT NULL,
`cDefine32` varchar(120) DEFAULT NULL,
`cDefine33` varchar(120) DEFAULT NULL,
`cDefine34` int(11) DEFAULT NULL,
`cDefine35` int(11) DEFAULT NULL,
`cDefine36` datetime DEFAULT NULL,
`cDefine37` datetime DEFAULT NULL,
`iAmount` decimal(19,4) DEFAULT NULL,
`iAmount_f` decimal(19,4) DEFAULT NULL,
`iAmount_s` double DEFAULT NULL,
`iVouchAmount` decimal(19,4) DEFAULT NULL,
`iVouchAmount_f` decimal(19,4) DEFAULT NULL,
`iVouchAmount_s` double DEFAULT NULL,
`dtZbjEndDate` datetime DEFAULT NULL,
`cExecID` varchar(30) DEFAULT NULL,
`cBusType` varchar(8) DEFAULT NULL,
PRIMARY KEY (`Auto_ID`,`dvouchdate`),
KEY `Ar_Detail_ibvid_ind` (`iBVid`),
KEY `Ar_Detail_iflag_ind` (`iFlag`),
KEY `Ar_Detail_SY` (`cProcStyle`,`cexch_name`,`cFlag`),
KEY `Ar_cPZID` (`cPZid`),
KEY `Ar_iClosesID` (`iClosesID`),
KEY `Ar_iCoClosesID` (`iCoClosesID`),
KEY `idx_Operator_Ar_Detail` (`cOperator`),
KEY `INDEX_Ar_Detail_cCoVouchID` (`cCoVouchType`,`cCoVouchID`),
KEY `INDEX_Ar_Detail_cVouchID` (`cVouchType`,`cVouchID`),
KEY `INDEX_Ar_Detail_HX` (`cDwCode`,`cexch_name`,`cCoVouchType`),
KEY `INDEX_Ar_Detail_HXZD` (`cProcStyle`,`cCancelNo`,`cFlag`),
KEY `IX_ar_detail_Mx_MIX1` (`cFlag`,`iFlag`,`cDwCode`,`dCreditStart`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
partition by range (year(dvouchdate)) (partition p2004 values less than (2005),
partition p2005 values less than (2006),
partition p2006 values less than (2007),
partition p2007 values less than (2008),
partition p2008 values less than (2009),
partition p2009 values less than (2010),
partition p2010 values less than (2011),
partition p2011 values less than (2012),
partition p2012 values less than (2013),
partition p2013 values less than (2014),
partition p2014 values less than (2015),
partition p2015 values less than (2016),
partition p2016 values less than (2017)
);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。