mysql 5.6 分区_Mysql5.6—分区表及独享表空间
1、先停止Mysql
[root@localhost~]#?/etc/init.d/mysqld?stop
Shutting?down?MySQL.[確定]
2、修改 /etc/my.cnf配置文件
[root@localhost~]#?vi?/etc/my.cnf
[mysqld]
innodb_file_per_table = 1
3、啟動Mysql
[root@localhost~]#?/etc/init.d/mysqld?start
Starting?MySQL..[確定]
4、連接到Mysql數(shù)據(jù)庫
[root@localhost~]#?mysql?-uroot?-p
Enter?password:
Welcome?to?the?MySQL?monitor.??Commands?end?with?;?or?\g.
Your?MySQL?connection?id?is?1
Server?version:?5.5.22-log?Source?distribution
Copyright?(c)?2000,?2011,?Oracle?and/or?its?affiliates.?All?rights?reserved.
Oracle?is?a?registered?trademark?of?Oracle?Corporation?and/or?its
affiliates.?Other?names?may?be?trademarks?of?their?respective
owners.
Type?'help;'?or?'\h'?for?help.?Type?'\c'?to?clear?the?current?input?statement.
mysql>?show?databases;
+--------------------+
|?Database???????????|
+--------------------+
|?information_schema?|
|?dbmonitor??????????|
|?mysql??????????????|
|?performance_schema?|
|?test???????????????|
+--------------------+
5?rows?in?set?(0.01?sec)
mysql> show plugins;
+-----------------------+--------+--------------------+---------+---------+
| Name ? ? ? ? ? ? ? ? ?| Status | Type ? ? ? ? ? ? ? | Library | License |
+-----------------------+--------+--------------------+---------+---------+
| binlog ? ? ? ? ? ? ? ?| ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| mysql_native_password | ACTIVE | AUTHENTICATION ? ? | NULL ? ?| GPL ? ? |
| mysql_old_password ? ?| ACTIVE | AUTHENTICATION ? ? | NULL ? ?| GPL ? ? |
| MEMORY ? ? ? ? ? ? ? ?| ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| MRG_MYISAM ? ? ? ? ? ?| ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| MyISAM ? ? ? ? ? ? ? ?| ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| CSV ? ? ? ? ? ? ? ? ? | ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| InnoDB ? ? ? ? ? ? ? ?| ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| INNODB_TRX ? ? ? ? ? ?| ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| INNODB_LOCKS ? ? ? ? ?| ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| INNODB_LOCK_WAITS ? ? | ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| INNODB_CMP ? ? ? ? ? ?| ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| INNODB_CMP_RESET ? ? ?| ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| INNODB_CMPMEM ? ? ? ? | ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| INNODB_CMPMEM_RESET ? | ACTIVE | INFORMATION SCHEMA | NULL ? ?| GPL ? ? |
| PERFORMANCE_SCHEMA ? ?| ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
| partition ? ? ? ? ? ? | ACTIVE | STORAGE ENGINE ? ? | NULL ? ?| GPL ? ? |
+-----------------------+--------+--------------------+---------+---------+
mysql>?use?dbmonitor;
Database?changed
5、創(chuàng)建分區(qū)表(history_text):
mysql>create table history_text
(
id bigint(20) unsigned default null,
itemid bigint(20) unsigned default null,
clock int(11) default 0,
value text default null,
ns int(11) default 0,
index itemid_idx (itemid),
primary key(id,clock)
) engine=Innodb
partition by range (clock)
(
partition p1_201502 values less than (unix_timestamp('2015-03-01')),
partition p1_201503 values less than (unix_timestamp('2015-04-01')),
partition p1_201504 values less than (unix_timestamp('2015-05-01')),
partition p1_201505 values less than (unix_timestamp('2015-06-01')),
partition p1_201506 values less than (unix_timestamp('2015-07-01')),
partition p1_201507 values less than (unix_timestamp('2015-08-01')),
partition p1_201508 values less than (unix_timestamp('2015-09-01')),
partition p1_201509 values less than (unix_timestamp('2015-10-01')),
partition p1_201510 values less than (unix_timestamp('2015-11-01')),
partition p1_201511 values less than (unix_timestamp('2015-12-01')),
partition p1_201512 values less than (unix_timestamp('2016-01-01')),
partition p1_201601 values less than (unix_timestamp('2016-02-01')),
partition p1_201602 values less than (unix_timestamp('2016-03-01')),
partition p1_201603 values less than (unix_timestamp('2016-04-01')),
partition p1_201604 values less than (unix_timestamp('2016-05-01')),
partition p1_201605 values less than (unix_timestamp('2016-06-01')),
partition p1_201606 values less than (unix_timestamp('2016-07-01')),
partition p1_201607 values less than (unix_timestamp('2016-08-01')),
partition p1_201608 values less than (unix_timestamp('2016-09-01')),
partition p1_201609 values less than (unix_timestamp('2016-10-01')),
partition p1_201610 values less than (unix_timestamp('2016-11-01')),
partition p1_201611 values less than (unix_timestamp('2016-12-01')),
partition p1_other_all values less than maxvalue
);
mysql>alter table?history_text add primary key(id,clock);6、檢查數(shù)據(jù)數(shù)據(jù)庫配置參數(shù)是否生效。
[root@localhost?data]#?ll? ? 總計?10900348? ? drwx------?2?mysql?mysql???????4096?03-20?09:40?dbmonitor? ?-rw-rw----?1?mysql?mysql?7266631680?03-20?10:29?ibdata1? ? -rw-rw----?1?mysql?mysql????5242880?03-20?10:30?ib_logfile0? ? -rw-rw----?1?mysql?mysql????5242880?03-20?10:30?ib_logfile1? ? drwxr-xr-x?2?mysql?root????????4096?03-18?00:18?mysql? ? -rw-rw----?1?mysql?mysql??????27338?03-18?00:18?mysql-bin.000001[root@localhost~]#?cd?/usr/local/mysql/data/dbmonitor/[root@localhostdbmonitor]#?ll總計?5112-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201503.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:34?history_text#P#p1_201504.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201505.ibd-rw-rw----?1?mysql?mysql?131072?03-18?10:06?history_text#P#p1_201506.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201507.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201508.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201509.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201510.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201511.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201512.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201601.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201602.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201603.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201604.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201605.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201606.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201607.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201608.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201609.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201610.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201611.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:35?history_text#P#p1_other_all.ibd7、查看分區(qū)表。mysql> select table_name, partition_name from information_schema.partitions-> where table_schema='dbmonitor' and table_name='history_text';+--------------+----------------+| table_name ? | partition_name |+--------------+----------------+| history_text | p1_201503 ? ? ?|| history_text | p1_201504 ? ? ?|| history_text | p1_201505 ? ? ?|| history_text | p1_201506 ? ? ?|| history_text | p1_201507 ? ? ?|| history_text | p1_201508 ? ? ?|| history_text | p1_201509 ? ? ?|| history_text | p1_201510 ? ? ?|| history_text | p1_201511 ? ? ?|| history_text | p1_201512 ? ? ?|| history_text | p1_201601 ? ? ?|| history_text | p1_201602 ? ? ?|| history_text | p1_201603 ? ? ?|| history_text | p1_201604 ? ? ?|| history_text | p1_201605 ? ? ?|| history_text | p1_201606 ? ? ?|| history_text | p1_201607 ? ? ?|| history_text | p1_201608 ? ? ?|| history_text | p1_201609 ? ? ?|| history_text | p1_201610 ? ? ?|| history_text | p1_201611 ? ? ?|| history_text | p1_other_all ? |+--------------+----------------+22 rows in set (0.01 sec)8、插入數(shù)據(jù)測試分區(qū)表。
mysql> delimiter //
mysql> create procedure insert_history()begindeclare var int;set var=0;while var<100000 doinsert into history_text values(var,var,1430496000,var,var);set var=var+1;end while;end;//
mysql> delimiter ;
mysql> call insert_test();
Query OK, 1 row affected (2 min 46.97 sec)
9、查看數(shù)據(jù)文件大小的變化。
[root@localhost?data]#?cd?dbmonitor/[root@localhost?dbmonitor]#?ll-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201503.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:34?history_text#P#p1_201504.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201505.ibd-rw-rw----?1?mysql?mysql?19922944?03-20?10:54?history_text#P#p1_201506.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201507.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201508.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201509.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201510.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201511.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201512.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201601.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201602.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201603.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201604.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201605.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201606.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201607.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201608.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201609.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201610.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:21?history_text#P#p1_201611.ibd-rw-rw----?1?mysql?mysql???131072?03-18?09:35?history_text#P#p1_other_all.ibd
[root@localhost?data]#?ll總計?10919648drwx------?2?mysql?mysql???????4096?03-20?09:40?dbmonitor-rw-rw----?1?mysql?mysql?7266631680?03-20?10:55?ibdata1-rw-rw----?1?mysql?mysql????5242880?03-20?10:55?ib_logfile0-rw-rw----?1?mysql?mysql????5242880?03-20?10:55?ib_logfile1drwxr-xr-x?2?mysql?root????????4096?03-18?00:18?mysql-rw-rw----?1?mysql?mysql??????27338?03-18?00:18?mysql-bin.000001-rw-rw----?1?mysql?mysql????1031892?03-18?00:18?mysql-bin.000002-rw-rw----?1?mysql?mysql????????126?03-18?00:23?mysql-bin.000003-rw-rw----?1?mysql?mysql????????126?03-18?00:25?mysql-bin.000004-rw-rw----?1?mysql?mysql??703646366?03-18?00:58?mysql-bin.000005-rw-rw----?1?mysql?mysql?1074397884?03-18?02:48?mysql-bin.000006-rw-rw----?1?mysql?mysql?1073854162?03-18?04:00?mysql-bin.000007-rw-rw----?1?mysql?mysql??973199491?03-18?04:43?mysql-bin.000008-rw-rw----?1?mysql?mysql????????126?03-18?09:19?mysql-bin.000009-rw-rw----?1?mysql?mysql???41826406?03-18?11:01?mysql-bin.000010-rw-rw----?1?mysql?mysql????????126?03-18?11:06?mysql-bin.000011-rw-rw----?1?mysql?mysql????????126?03-18?14:03?mysql-bin.000012-rw-rw----?1?mysql?mysql???????2175?03-18?16:48?mysql-bin.000013-rw-rw----?1?mysql?mysql????????107?03-18?23:06?mysql-bin.000014-rw-rw----?1?mysql?mysql????????107?03-19?08:49?mysql-bin.000015-rw-rw----?1?mysql?mysql????5720758?03-20?10:29?mysql-bin.000016-rw-rw----?1?mysql?mysql???19741312?03-20?10:55?mysql-bin.000017-rw-rw----?1?mysql?mysql????????323?03-20?10:30?mysql-bin.indexdrwx------?2?mysql?mysql???????4096?03-18?00:18?performance_schemadrwxr-xr-x?2?mysql?root????????4096?03-18?15:14?test
注釋:發(fā)現(xiàn)只有單獨的表空間數(shù)據(jù)文件在增大,mysql的元數(shù)據(jù)文件不變化。
10、刪除分區(qū)表中的數(shù)據(jù),減少數(shù)據(jù)文件的大小,清理空間。
mysql> alter table history_text truncate partition p1_201506;
Query OK, 0 rows affected (0.09 sec)
[root@localhost?dbmonitor]#?ll-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201503.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:34?history_text#P#p1_201504.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201505.ibd-rw-rw----?1?mysql?mysql?131072?03-20?11:01?history_text#P#p1_201506.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201507.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201508.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201509.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201510.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201511.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201512.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201601.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201602.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201603.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201604.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201605.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201606.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201607.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201608.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201609.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201610.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:21?history_text#P#p1_201611.ibd-rw-rw----?1?mysql?mysql?131072?03-18?09:35?history_text#P#p1_other_all.ibd
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的mysql 5.6 分区_Mysql5.6—分区表及独享表空间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UCloud首尔机房整体热迁移是这样炼成
- 下一篇: mysql在线复制_mysql如何在线修