为MySQL数据文件ibdata1瘦身
欢迎进入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]

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
