前提條件是主從同步操做完成(主從同步的前提是兩個數據庫表結構必須同樣)
先看一下mysql配置文件
vi /usr/local/mysql/my.cnf
配置內容:------------------------------------------------------------------------------------
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
#default-storage-engine=INNODB
default-character-set=utf8
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = /usr/local/mysql/data/mysql3306.pid
log-error= /usr/local/mysql/logs/error.log
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 1500
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 2250
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 96M
max_heap_table_size = 96M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
event_scheduler=ON
###***slowqueryparameters
long_query_time = 0.1
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/logs/slow.log
###***binlogparameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
binlog_format=MIXED
expire_logs_days=7
###***master-slavereplicationparameters
server-id=1
binlog-do-db=zabbix #只同步zabbix數據庫
innodb_buffer_pool_size = 128M
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
#slave-skip-errors=all
[mysqldump]
quick
max_allowed_packet=32M
配置文件下載:https://pan.baidu.com/s/1Qd5oWsAQYESzn3pne8yBkg 密碼:wanb
首先刪除表
use zabbix
drop table history;
drop table history_text;
drop table history_log;
drop table history_str;
drop table history_uint;
drop table trends;
drop table trends_uint;
新建數據表
範例:(1471910400)==(UNIX_TIMESTAMP("2017-04-01 00:00:00"))
注意:時間設置爲自修改日期到月底。
執行如下操做新建表:
CREATE TABLE `history` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` double(16,4) NOT NULL DEFAULT '0.0000',
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
ROW_FORMAT=COMPACTmysql
PARTITION BY RANGE (`clock`)
(PARTITION p20171101 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-1 23:59:00")) ENGINE = InnoDB,
PARTITION p20171102 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-2 23:59:00")) ENGINE = InnoDB,
PARTITION p20171103 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-3 23:59:00")) ENGINE = InnoDB,
PARTITION p20171104 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-4 23:59:00")) ENGINE = InnoDB,
PARTITION p20171105 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-5 23:59:00")) ENGINE = InnoDB,
PARTITION p20171106 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-6 23:59:00")) ENGINE = InnoDB,
PARTITION p20171107 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-7 23:59:00")) ENGINE = InnoDB,
PARTITION p20171108 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-8 23:59:00")) ENGINE = InnoDB,
PARTITION p20171109 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-9 23:59:00")) ENGINE = InnoDB,
PARTITION p20171110 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-10 23:59:00")) ENGINE = InnoDB,
PARTITION p20171111 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-11 23:59:00")) ENGINE = InnoDB,
PARTITION p20171112 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-12 23:59:00")) ENGINE = InnoDB,
PARTITION p20171113 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-13 23:59:00")) ENGINE = InnoDB,
PARTITION p20171114 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-14 23:59:00")) ENGINE = InnoDB,
PARTITION p20171115 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-15 23:59:00")) ENGINE = InnoDB,
PARTITION p20171116 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-16 23:59:00")) ENGINE = InnoDB,
PARTITION p20171117 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-17 23:59:00")) ENGINE = InnoDB,
PARTITION p20171118 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-18 23:59:00")) ENGINE = InnoDB,
PARTITION p20171119 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-19 23:59:00")) ENGINE = InnoDB,
PARTITION p20171120 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-20 23:59:00")) ENGINE = InnoDB,
PARTITION p20171121 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-21 23:59:00")) ENGINE = InnoDB,
PARTITION p20171122 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-22 23:59:00")) ENGINE = InnoDB,
PARTITION p20171123 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-23 23:59:00")) ENGINE = InnoDB,
PARTITION p20171124 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-24 23:59:00")) ENGINE = InnoDB,
PARTITION p20171125 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-25 23:59:00")) ENGINE = InnoDB,
PARTITION p20171126 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-26 23:59:00")) ENGINE = InnoDB,
PARTITION p20171127 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-27 23:59:00")) ENGINE = InnoDB,
PARTITION p20171128 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-28 23:59:00")) ENGINE = InnoDB,
PARTITION p20171129 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-29 23:59:00")) ENGINE = InnoDB,
PARTITION p20171130 VALUES LESS THAN (UNIX_TIMESTAMP("2017-11-30 23:59:00")) ENGINE = InnoDB
);
。。。。。。
sql文件根據實際狀況修改
連接:https://pan.baidu.com/s/1vUPTQOIAWTHRN1Y1LWnkbQ 密碼:cgxx
依次建立新的表結構
修改自動分區腳本中用戶名和密碼,拷貝自動分區腳本到指定目錄下
主從都須要添加
chmod 755 autopartitions.sh
chown mysql.mysql autopartitions.sh
3.設置後臺計劃任務自動分區
執行crontab -e
01 01 * * * /data/mysqldb/autopartitions.sh
腳本下載
連接:https://pan.baidu.com/s/18N8rkh2vDhltq9DVjq9EhQ 密碼:7o0l
是否成功能夠參考mysql配置文件中對應庫文件下是否有基於日期的文件
主庫
從庫