search
HomeDatabaseMysql Tutorial为MySQL数据文件ibdata1瘦身
为MySQL数据文件ibdata1瘦身Jun 07, 2016 pm 03:20 PM
lmysqldatadocumentlose weightEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 MySQL在运行一段时间后,ibdata1的文件会增长大小,就算删除了表的数据,ibdata1的体积也不会减

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  MySQL在运行一段时间后,ibdata1的文件会增长大小,就算删除了表的数据,ibdata1的体积也不会减小。由于硬盘空间有限,这样一直膨胀下去磁盘空间接近崩溃。今天在导出数据的时候就发现了,磁盘竟然满了,明明预留了1个月的用量,1周就占满了,下面就要给ibdata1做个瘦身。

  1. 系统环境

  Linux Ubuntu 13.04 64bit server

  ~ uname -a

  Linux d2 3.8.0-21-generic #32-Ubuntu SMP Tue May 14 22:16:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

  ~ cat /etc/issue

  Ubuntu 13.04 \n \l

  MySQL: 5.5.31-0ubuntu0.13.04.1

  ~ mysql --version

  mysql  Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (x86_64) using readline 6.2

  硬盘:36G+4G+4G+36G

  ~ df -h

  Filesystem                    Size  Used Avail Use% Mounted on

  /dev/mapper/server3--vg-root   36G   31G  3.2G  91% /

  none                          4.0K     0  4.0K   0% /sys/fs/cgroup

  udev                          4.1G  1.1G  3.0G  26% /dev

  tmpfs                         824M  280K  823M   1% /run

  none                          5.0M     0  5.0M   0% /run/lock

  none                          4.1G  3.4G  729M  83% /run/shm

  none                          100M     0  100M   0% /run/user

  /dev/vda1                     228M   30M  187M  14% /boot

  192.168.1.10:/home/amg/data    36G   13G   21G  39% /home/amg/data

  MySQL的ibdata1占用空间:20G

  ~ cd /var/lib/mysql

  ~ ls -l

  drwxr-xr-x 2 mysql mysql        4096 Aug  2 19:38 CB

  drwxr-xr-x 2 mysql mysql        4096 Jun 24 23:08 conan

  drwxr-xr-x 2 mysql mysql        4096 Jun  2 00:52 dbwordpress

  -rwxr-xr-x 1 root  root            0 May 23 00:48 debian-5.5.flag

  -rwxr-xr-x 1 mysql mysql 20101201920 Aug  2 20:08 ibdata1

  -rwxr-xr-x 1 mysql mysql     5242880 Aug  2 20:08 ib_logfile0

  -rwxr-xr-x 1 mysql mysql     5242880 Aug  2 19:38 ib_logfile1

  drwxr-xr-x 2 mysql mysql        4096 Jun 26 09:03 Macro

  drwxr-xr-x 2 mysql root         4096 May 23 00:48 mysql

  -rwxr-xr-x 1 root  root            6 May 23 00:48 mysql_upgrade_info

  drwxr-xr-x 2 mysql mysql        4096 May 23 00:48 performance_schema

  drwxr-xr-x 2 mysql mysql        4096 May 23 00:53 phpmyadmin

  drwxr-xr-x 2 mysql root         4096 May 23 00:48 test

  drwxr-xr-x 2 mysql mysql        4096 Jul 22 14:09 TF

  drwxr-xr-x 2 mysql mysql        4096 Jun  2 01:04 wordpress

  业务数据表

  mysql> show tables;

  +-----------------+

  | Tables_in_CB    |

  +-----------------+

  | NSpremium       |

  | cb_hft          |

  | cb_hft_20130801 |

  | cb_hft_20130802 |

  +-----------------+

  4 rows in set (0.00 sec)

  2. 发现问题

  ibdata1单个文件占用20G大小。

  1. MySQL默认设置,没有按表空间分离数据,所有的表的数据都被放到ibdata1文件中。

  2. 业务操作,每天会产生一张表cb_hft,晚上的时候对表进行重命名。

  RENAME TABLE cb_hft TO cb_hft_20130801;

  create table cb_hft like cb_hft_20130801;

[1] [2] [3] 

为MySQL数据文件ibdata1瘦身

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.