沈斌
2017-11-19 f647bcf01c53d0e007c54d030193d11a8305e9b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var mysql = require('mysql');
var moment = require('moment');
var config = require('./config');
 
var mysqlClient = mysql.createConnection(config.mysql);
 
mysqlClient.connect(function(error) {
    if (error) return;
    //console.log("connected to MySQL");
});
 
var partition_name = "p" + moment().add(config.count, 'd').format("YYYYMMDD");
var partition_date = moment().add(config.count + 1, 'd').format("YYYYMMDD");
 
var sql = "ALTER TABLE history ADD PARTITION (PARTITION " + partition_name + " VALUES LESS THAN ('" + partition_date + "'))";
console.log(sql);
 
mysqlClient.query(sql, function (error, results, fields) {
    if (error) throw error;
    //console.log(results);
    //console.log(fields);
});
 
mysqlClient.end();