MySQL数据库分区修改【原创】
之前有个表分区添加时s201607添加成s201617,所以在查询7月份数据时报错
错误的
alter table statistics_ticket add partition (partition s201617 values less than (201607));
正确的
alter table statistics_ticket add partition (partition s201607 values less than (201607));
因为range的分区没法直接修改,只能先删除最后分区至要修改的分区,在重新添加分区,再添加数据。
具体操作步骤:
1)完整表备份
mysqldump -u root -p'***' -t databasename tablename > /home/statistics_ticket_20160819_1800.sql &
2)7、8月表数据备份不导出结构
mysqldump -u root -p'***' -t databasename tablename --where="FLIGHT_DATE between '2016-07-01' and '2016-08-31'" > /home/statistics_ticket_20160819_0708_data_1800.sql &
在备机上进行完整备份
/home/backup/script/basebackup.bash
3)先统计表有多少行
select count(*) from statistics_ticket where FLIGHT_DATE between '2016-07-01' and '2016-07-31';
select count(*) from statistics_ticket where FLIGHT_DATE between '2016-07-01' and '2016-08-31';
4)删除分区
测试
alter table statistics_ticket drop partition s201901;
alter table statistics_ticket drop partition s201617;
alter table statistics_ticket drop partition s201608;
alter table statistics_ticket drop partition s201609;
alter table statistics_ticket drop partition s201610;
alter table statistics_ticket drop partition s201611;
alter table statistics_ticket drop partition s201612;
alter table statistics_ticket drop partition s201701;
alter table statistics_ticket drop partition s201702;
alter table statistics_ticket drop partition s201703;
alter table statistics_ticket drop partition s201704;
alter table statistics_ticket drop partition s201705;
alter table statistics_ticket drop partition s201706;
alter table statistics_ticket drop partition s201707;
alter table statistics_ticket drop partition s201708;
alter table statistics_ticket drop partition s201709;
alter table statistics_ticket drop partition s201710;
alter table statistics_ticket drop partition s201711;
alter table statistics_ticket drop partition s201712;
alter table statistics_ticket drop partition s201801;
alter table statistics_ticket drop partition s201802;
alter table statistics_ticket drop partition s201803;
alter table statistics_ticket drop partition s201804;
alter table statistics_ticket drop partition s201805;
alter table statistics_ticket drop partition s201806;
alter table statistics_ticket drop partition s201807;
alter table statistics_ticket drop partition s201808;
alter table statistics_ticket drop partition s201809;
alter table statistics_ticket drop partition s201810;
alter table statistics_ticket drop partition s201811;
alter table statistics_ticket drop partition s201812;
alter table statistics_ticket drop partition s201901;
在查看分区添加是否成功
show create table statistics_ticket\G;
5)添加分区
alter table statistics_ticket add partition (partition s201607 values less than (201607));
alter table statistics_ticket add partition (partition s201608 values less than (201608));
alter table statistics_ticket add partition (partition s201609 values less than (201609));
alter table statistics_ticket add partition (partition s201610 values less than (201610));
alter table statistics_ticket add partition (partition s201611 values less than (201611));
alter table statistics_ticket add partition (partition s201612 values less than (201612));
alter table statistics_ticket add partition (partition s201701 values less than (201701));
alter table statistics_ticket add partition (partition s201702 values less than (201702));
alter table statistics_ticket add partition (partition s201703 values less than (201703));
alter table statistics_ticket add partition (partition s201704 values less than (201704));
alter table statistics_ticket add partition (partition s201705 values less than (201705));
alter table statistics_ticket add partition (partition s201706 values less than (201706));
alter table statistics_ticket add partition (partition s201707 values less than (201707));
alter table statistics_ticket add partition (partition s201708 values less than (201708));
alter table statistics_ticket add partition (partition s201709 values less than (201709));
alter table statistics_ticket add partition (partition s201710 values less than (201710));
alter table statistics_ticket add partition (partition s201711 values less than (201711));
alter table statistics_ticket add partition (partition s201712 values less than (201712));
alter table statistics_ticket add partition (partition s201801 values less than (201801));
alter table statistics_ticket add partition (partition s201802 values less than (201802));
alter table statistics_ticket add partition (partition s201803 values less than (201803));
alter table statistics_ticket add partition (partition s201804 values less than (201804));
alter table statistics_ticket add partition (partition s201805 values less than (201805));
alter table statistics_ticket add partition (partition s201806 values less than (201806));
alter table statistics_ticket add partition (partition s201807 values less than (201807));
alter table statistics_ticket add partition (partition s201808 values less than (201808));
alter table statistics_ticket add partition (partition s201809 values less than (201809));
alter table statistics_ticket add partition (partition s201810 values less than (201810));
alter table statistics_ticket add partition (partition s201811 values less than (201811));
alter table statistics_ticket add partition (partition s201812 values less than (201812));
alter table statistics_ticket add partition (partition s201901 values less than (201901));
在查看分区添加是否成功
show create table statistics_ticket\G;
导入数据
source /home/
看统计表有多少行是否和之前的一致
select count(*) from statistics_ticket where FLIGHT_DATE between '2016-07-01' and '2016-07-31';
select count(*) from statistics_ticket where FLIGHT_DATE between '2016-07-01' and '2016-08-31';
6)让用户测试
MySQL数据库分区修改【原创】的更多相关文章
- MySQL数据库分区的概念与2大好处(1)
我们大家都知道通过MySQL数据库分区(Partition)可以提升MySQL数据库的性能,那么到底什么是MySQL数据库分区呢?以及其实际应用的好处的表现有哪些呢?以下的文章就是对这些内容的描述. ...
- mysql数据库分区功能及实例详解
分区听起来怎么感觉是硬盘呀,对没错除了硬盘可以分区数据库现在也支持分区了,分区可以解决大数据量的处理问题,下面一起来看一个mysql数据库分区功能及实例详解 一,什么是数据库分区 前段时间写过一篇 ...
- Mysql 数据库之修改标的结构
比如我们新建一user表 create table user( id int unsigned auto_increment primary key, name varchar(60) not nul ...
- MySql数据库安装&修改密码&开启远程连接图解
相关工具下载地址: mysql5.6 链接:http://pan.baidu.com/s/1o8ybn4I密码:aim1 SQLyog-12.0.8 链接:http://pan.baidu.com/s ...
- Win7安装mysql数据库、修改默认密码
学习和使用myslq数据库半年时间,mysql对于每一个开发人员都不会陌生.今天对电脑重装系统,为了方面测试在个人PC上安装了mysql数据库.以一下是整个安装过程. 一.下载mysql 1.首先需要 ...
- mysql数据库分区和分表
转载自 https://www.cnblogs.com/miketwais/articles/mysql_partition.html https://blog.csdn.net/vbirdbest/ ...
- windows安装mysql数据库并修改密码
1.下载 MySQL Community Server https://dev.mysql.com/downloads/mysql/ 2.解压 如果想要让MySQL安装在指定目录,那么就将解压后的文件 ...
- mysql数据库如何修改密码及权限分配
如何修改Mysql密码 Mysql用户密码采用md5加密函数加密(单向加密) SELECT PASSWORD('root'); -- *81F5E21E35407D884A6CD4A731AEBFB6 ...
- mysql数据库 安装 (原创)
1.首先下载mysql 数据库,我安装的是mysql5.1版本,直接安装就行,但是如果以后你想在数据库里显示中文的话,要把字符集设置为gb2312 2.配置数据源odbc. mysql-connec ...
随机推荐
- 用PHP提取MYSQL二进制日志的SQL语句
上一篇说道,在从日志提取出SQL语句的时候,碰到了一句SQL跨了N行无法提取.后来在网上搜了两句shell: sed -n '/^INSERT /,/;/p' log.sql > log_ins ...
- Microsoft Visual Studio 2012正式版官方下载
Microsoft Visual Studio 2012正式版官方下载 首先声明,看到园子里还没有类似的新闻,所以斗胆发首页,如有不妥之处,请移除并谅解. 虽然之前已经又用到泄露的MSDN正式版,但今 ...
- Sass与Compress实战:第二章
1.使用变量 Sass使用$符号来标识变量,比如$highlight-color. 1.1声明变量 Sass声明变量和CSS声明属性很像: $highlight-color : #abcdef; 这意 ...
- 关于JavaScript的小笔记
1.当 JavaScript 中的变量被声明的时候,程序内部会给它一个初始值 undefined.当你对一个值为 undefined 的变量进行运算操作的时候,算出来的结果将会是 NaN,NaN 的意 ...
- ZUFE(周赛) 2326 交换字母(STL)
Time Limit: 1 Sec Memory Limit: 128 MB Description 有一个长度为n的字符串(只包含小写字母),操作m次,每次操作交换两个字母,输出最终字符串. In ...
- 一些css3的特效 javascript的window对象 定时器 延时器等ing...
风车转动代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...
- java邮件发送(以163邮箱为例)
1.首先应该开通163邮箱的smtp和pop3,得到授权码 2.其次建立一个web项目,否则需要倒jar包mail.jar 3.创建一个类 4.注意:邮件内容必须为正式话语,否则系统会认为是垃圾邮件而 ...
- iOS页面间传值的六种方式
一般ios页面间的传值方式分为6种:1.属性传值:2.block:3.delegate:4.UserDefault:5.单例:6.通知. 0&1.block 先说我最常用的block吧,属性传 ...
- WimTool(Wim映像处理工具) V1.30.2011.501 免费绿色版
软件名称: WimTool(Wim映像处理工具) V1.30.2011.501 免费绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinX ...
- 华硕笔记本怎么进入PE之前的BIOS设置
1.先要制作一个U盘的PE启动盘,建议使用WIN8 PE 2.将制作好的PE启动盘接上电脑,开机按F2键进入BIOS ,先将[Secure]菜单下[Secure Boot Control]选项设置为[ ...