1. 按照原历史表新增一个新表(空表):
mysql> create table history_log_new ...;
2. 给历史表重命名,并将新表重命名为历史表:
mysql> RENAME TABLE history_log to history_log_20151217, history_log_new to history_log;
mysqldump -uroot -p -h --databases --tables user --where='' > 导出数据
3:查看binlog日志
mysqlbinlog --start-datetime='2017-12-08 04:56:02' --stop-datetime='2017-12-08 04:56:10' --base64-output=decode-rows -v mysql-bin.000264
4:高级group by使用 利用高级时间函数 对时间分组(created是创建的实时时间, 需要用date_format格式化到每日时间)
SELECT count(*),date_format(created,"%y-%m-%d") as date FROM cn_send_phone_history group by date_format(created,"%yyyy-%m-%d");
5:查看mysql存储
USE information_schema;
SELECT TABLE_SCHEMA, SUM(DATA_LENGTH)/1024 FROM TABLES GROUP BY TABLE_SCHEMA;
6:批量truncate表
SELECT CONCAT("TRUNCATE TABLE `", t.TABLE_NAME, '`;') FROM information_schema.`TABLES` t WHERE t.TABLE_NAME LIKE "l3%";