ibdata1是mysql使用InnoDB引擎的時候需要使用的檔案。這個檔案有的時候會變得很大,并且在你删除資料的時候,檔案也不減小。今天就碰到了一次,導緻所有的/var分區都被占用光了。 下面是處理超大ibddata1檔案的步驟: 1. 對每張表使用單獨的innoDB檔案, 修改/etc/my.cnf檔案 [mysqld]
innodb_file_per_table 目的很明确,我們可以單獨删除每個檔案 2. 導出所有的資料,重建資料庫,然後恢複資料: # /usr/bin/mysqldump -R -q --all-databases > /temp/all.sql
# service mysqld stop
# rm -fr /var/lib/mysql/*
# /usr/bin/mysql_install_db
# service mysqld restart
# mysql < /tmp/all.sql 3. /var/lib/mysql的每個資料庫下面,都有會很多的.ibd檔案。這些分散的.ibd檔案取代了原來的那個ibddata1。 以後删除資料庫的時候,直接删除某個資料庫的目錄就可以了。 mysql> show engines;
+------------+---------+----------------------------------------------------------------+
| Engine | Support | Comment |
+------------+---------+----------------------------------------------------------------+
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys |
| BerkeleyDB | YES | Supports transactions and page-level locking |
| BLACKHOLE | NO | /dev/null storage engine (anything you write to it disappears) |
| EXAMPLE | NO | Example storage engine |
| ARCHIVE | NO | Archive storage engine |
| CSV | NO | CSV storage engine |
| ndbcluster | NO | Clustered, fault-tolerant, memory-based tables |
| FEDERATED | NO | Federated MySQL storage engine |
| MRG_MYISAM | YES | Collection of identical MyISAM tables |
| ISAM | NO | Obsolete storage engine |
+------------+---------+----------------------------------------------------------------+
12 rows in set (0.00 sec) For InnoDB tables, OPTIMIZE TABLE is mapped to ALTER TABLE, which rebuilds the table to update index statistics and free unused space in the clustered index.
是以不會直接來減少ibdata的檔案尺寸。
減少ibdata的方法如下
- 1. 用mysqldump等工具導出資料 - 2. 停止 mysqld
- 3. 删除ibdata*, ib_logfile* 檔案
- 4. 重新啟動 mysqld(這時mysqld就會自動建立 idbdata*, ib_logfile* 檔案)
- 5. 将到出來的資料導回去,體積才會減小。 |