沈斌
2018-01-22 a8e1099b42befac8bdf8ead48568c8248920399d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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");
});
 
for(var i = 0; i < 12; i++) {
    var partition_name = "p" + moment().add(-64 + i, 'd').format("YYYYMMDD");
    console.log(partition_name);
 
    sql = "ALTER TABLE history DROP PARTITION " + partition_name;
    console.log(sql);
 
    mysqlClient.query(sql, function (error, results, fields) {
        if (error) throw error;
        //console.log(results);
        //console.log(fields);
    });
}
 
mysqlClient.end();