mysql mariadb 删除表中的数据时数据库变大
删除表中数据以前
[root@RM uar3]# du -sh *
3.3G apache-tomcat-7.0.54
150M instalRM4UAR
0 mariadb
903M mariadb-5.5.33a-linux-x86_64
64G mariadb-data
4.2G realmonitor
8.0K rm_netelement_s1u.sql
40K switchFlowReportWeb
0 tomcat
删除表数据
delete from nagios_statehistory where state_time < '2017-01-01 00:00:00';
delete from alarm_info where alarm_time < '2017-01-01 00:00:00';
delete from switchflowout where CreateTime < '1483200000';
delete from switchflowin where CreateTime < '1483200000';
删除表数据后
[root@RM uar3]# du -sh *
3.3G apache-tomcat-7.0.54
150M instalRM4UAR
0 mariadb
903M mariadb-5.5.33a-linux-x86_64
70G mariadb-data
4.2G realmonitor
8.0K rm_netelement_s1u.sql
40K switchFlowReportWeb
0 tomcat
DELETE只是将数据标识位删除,并没有整理数据文件,当插入新数据后,会再次使用这些被置为删除标识的记录空间。
最简单的:optimize table phpernote_article;对表进行优化
优化时出现下面问题
mysql> optimize table nagios_statehistory;
+---------------------------------+----------+----------+----------------------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+---------------------------------+----------+----------+----------------------------------------------------------------------------------------------------+
| realmonitor.nagios_statehistory | optimize | Error | Table './realmonitor/nagios_statehistory' is marked as crashed and last (automatic?) repair failed |
| realmonitor.nagios_statehistory | optimize | Error | Table 'nagios_statehistory' is marked as crashed and last (automatic?) repair failed |
| realmonitor.nagios_statehistory | optimize | error | Corrupt |
+---------------------------------+----------+----------+----------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)
修复数据表操作:
停止数据库
[root@RM uar3]# /etc/init.d/mariadb stop
Shutting down MySQL..
1、service mysqld stop;
2、cd /var/lib/mysql/db_name/
3、myisamchk -r tablename.MYI (修复单张数据表)
myisamchk -r *.MYI (修复所有数据表)
[root@RM realmonitor]# myisamchk -r nagios_statehistory.MYI
- recovering (with sort) MyISAM-table 'nagios_statehistory.MYI'
Data records: 807753
- Fixing index 1
Data records: 1042062
[root@RM realmonitor]# /etc/init.d/mariadb start
Starting MySQL... [ OK ]
mysql> optimize table nagios_statehistory;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 6
Current database: realmonitor +---------------------------------+----------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------------------------------+----------+----------+----------+
| realmonitor.nagios_statehistory | optimize | status | OK |
+---------------------------------+----------+----------+----------+
1 row in set (3.64 sec)
mysql mariadb 删除表中的数据时数据库变大的更多相关文章
- PHP mysql 删除表中所有数据只保留一条
DELETE FROM `logs` WHERE wangzhi='www.juhutang.com' and id<>101072; 上面这段代码的意思为 删除表logs中 所有字段wa ...
- 触发器修改后保存之前的数据 表中插入数据时ID自动增长
create or replace trigger t before update on test5 for each rowbegin insert into test55 values (:old ...
- ROWID面试题-删除表中重复数据(重复数据保留一个)
/* ROWID是行ID,通过它一定可以定位到r任意一行的数据记录 ROWID DNAME DEPTNO LOC ------------------ ------------------------ ...
- Navicat for MySQL怎么往表中填数据
只有往表中更新数据,数据库才会起到真正的作用. 工具/原料 仔细阅读 方法/步骤 1.打开数据库,首先连接localhost,如图所示. 2.连接成功后,右侧便会显示已经建成的表,找到要修改的表, ...
- MySQL 数据库删除表中重复数据
采集数据的时候,由于先期对页面结构的分析不完善,导致采漏了一部分数据.完善代码之后重新运行 Scrapy,又采集了一些重复的数据,搜了下删除重复数据的方法. N.B. 删除数据表的重复数据时,请先备份 ...
- 查询和删除表中重复数据sql语句
1.查询表中重复数据.select * from peoplewhere peopleId in (select peopleId from people group by ...
- mysql 定期删除表中无用数据
MySQL5.1.x版本中引入了一项新特性EVENT,定期执行某些事物,这可以帮助我们实现定期执行某个小功能,不在依赖代码去实现. 我现在有一张表,这张表中的数据有个特点,每天都会有大量数据插入,但是 ...
- mysql中在表中insert数据时,有重复主键id时,变成update
MySQL 自4.1版以后开始支持INSERT … ON DUPLICATE KEY UPDATE语法 例如: id name sex age 1 kathy male 23 2 Javer f ...
- MySQL 删除表中所有数据
方法一:使用 delete from [表名] 生成日志 方法二:使用 truncate table [表名] 无日志生成 两种方式删除后再插入数据,第一条id的值不一样 方法一: 方法二 ...
随机推荐
- python数据分析工具包(3)——matplotlib(一)
前两篇文章简单介绍了科学计算Numpy的一些常用方法,还有一些其他内容,会在后面的实例中学习.下面介绍另一个模块--Matplotlib. Matplotlib是一个Python 2D绘图库,试图让复 ...
- win7本地连接消失
可能原因一 驱动程序错误: 右键"计算机"图标 - "属性" - 设备管理器现在在设备管理器下面找到"网络适配器",在下面的网卡驱动中发现有 ...
- Jenkins gitlab vue,angular,react 自动化构建【原】
大致思路,(本篇主要讲vue ,当然了 angular react 也是一样配置) ,转发请注明原链接,谢谢 :) 1. 服务器上面配置jenkins (安装配置,不介绍) 2.新建item 自由风格 ...
- Python:注释
什么是注释? 注销:不参与执行 解释代码:有人习惯把代码解释放边上,建议放上边. 1)单行注释以 # 开头 # 需求12:键盘输入正整数n,求出n与其反序之和并输出例如:123反序321输出123+3 ...
- css命名整理
.container { width: 720px; background: #fafafa; border: 2px dashed #999; padding: 10px; float: left ...
- Mysql字符串截取总结:left()、right()、substring()、substring_index()
同步首发:http://www.yuanrengu.com/index.php/20171226.html 在实际的项目开发中有时会有对数据库某字段截取部分的需求,这种场景有时直接通过数据库操作来实现 ...
- 35 个 jQuery 小技巧
1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return ...
- centos7 yum与Python3冲突
虽然标题不严谨,但是,我自己尝试了多次,在安装了Python3.6后,yum无法同步Python.所以采用网上抄来抄去的做法,将yum指定使用Python2,凡是需要安装与Python相关的模块,使用 ...
- CNN 卷积层输入Map大小计算
对于输出的size计算: out_height=((input_height - filter_height + padding_top+padding_bottom)/stride_height ) ...
- ansible基本使用教程
转载请注明出处http://www.cnblogs.com/chenxianpao/p/7360349.html 一. 介绍 1. 简介 ansible是新出现的自动化运维工具,基于Pytho ...