分成2步:
2.將原表資料插入新錶
insert into 目標表 select * from **表;
總結:按月份進行的分表,按照月份內查詢資料的話,速度是會高於原表.create table met_shopv2_order_copy1 (
`id` int(11) not null auto_increment,
`orderid` varchar(20) character set utf8 collate utf8_bin not null comment '訂單id',
`type` int(1) not null comment '訂單型別',
`uid` int(11) not null comment '使用者id',
`username` varchar(50) character set utf8 collate utf8_general_ci not null comment '使用者名稱',
`state` int(2) not null comment '訂單狀態',
`tel` varchar(20) character set utf8 collate utf8_general_ci not null comment '**',
`email` varchar(50) character set utf8 collate utf8_general_ci not null comment '郵件',
`address` varchar(500) character set utf8 collate utf8_general_ci not null comment '收貨位址',
`price` double not null comment '商品金額',
`cprice` double not null comment '修改總金額',
`tprice` double not null comment '訂單總金額',
`discount` double not null comment '折扣**',
`discount_info` varchar(200) character set utf8 collate utf8_general_ci not null comment '折扣資訊',
`discount_use` int(1) not null comment '修改總金額後是否可以繼續使用折扣',
`freight` double not null comment '運費',
`cinfo` varchar(50) character set utf8 collate utf8_general_ci not null comment '物流公司',
`oinfo` varchar(50) character set utf8 collate utf8_general_ci not null comment '物流單號',
`paytype` int(1) not null comment '付款方式',
`payinfo` varchar(200) character set utf8 collate utf8_general_ci not null comment '付款資訊',
`invoice` int(1) not null comment '是否需要發票',
`invoice_info` varchar(500) character set utf8 collate utf8_general_ci not null comment '發票資訊',
`remark` varchar(1000) character set utf8 collate utf8_general_ci not null comment '備註',
`rtime` int(11) not null comment '下訂單時間',
`ptime` int(11) not null comment '付款時間',
`stime` int(11) not null comment '發貨時間',
`ctime` int(11) not null comment '關閉訂單時間',
`search` text character set utf8 collate utf8_general_ci not null comment '資訊搜尋字段',
`lang` varchar(50) character set utf8 collate utf8_general_ci not null comment '所屬語言',
primary key (id,ptime) using btree,//原表中只有id是主鍵,但分表的話,是要求分表條件也是主鍵
index `orderid`(`orderid`) using btree,
index `idx_shop_order_uid`(`uid`) using btree,
index `id`(`id`) using btree,
index `uid`(`uid`) using btree,
index `state`(`state`) using btree
) engine = myisam character set = utf8 collate = utf8_general_ci row_format = dynamic
partition by range (ptime)//range後是表分割槽的條件欄位.
(
partition p_201803 values less than (1522512000),//格式化過的時間
partition p_201804 values less than (1525104000),
partition p_201805 values less than (1527782400),
partition p_dec values less than maxvalue );
insert into met_shopv2_order_copy1 select * from met_shopv2_order;
但同時查幾個月的資料時,原表速度反而略高於分表後的資料.
參考資料:
mysql的分割槽字段必須包含主鍵-介紹以及解決方法
mysql中把乙個表的資料批量匯入另乙個表中
MySQL單機多例項實操
mysql的安裝主要分 大家在做單機多例項的時候對於兩個例項都是rpm的和免編譯安裝的都比較熟悉,也比較簡單 複製乙個my.cnf的配置檔案,修改一下datadir和埠號 初始化啟動 在登入的時候注意加上 p選項,指定一下埠號啟動就可以了 當然還有一種情況就是 第乙個例項安裝的是rpm安裝,第二個例...
mysql實操總結(基礎篇 上)
基礎篇 sql介紹及mysql安裝 一 結構化查詢語句 structured query language 簡稱sql 1 啟動mysql sudo service mysql start mysql u root 2 檢視資料庫 mysql show databases 3 連線資料庫 mysql...
redis備份實操
終於發布了個人的第乙個課程 redis備份實操,位址 1 不能搞出問題 虛擬機器測試環境不擔心這個啊 2 任務得在夜間進行 白天業務高峰期,不適合做維護 3 必須考慮可用性,得把資料備份到其他的系統上。我的搞法是 1 準備乙個資料校驗環境,安裝上redis,用於備份檔案匯入。通過對比生產環境redi...