为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

AI Hentai Generator
Generate AI Hentai for free.

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

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA
