ibdata1是mysql使用InnoDB引擎的時(shí)候需要使用的文件。這個(gè)文件有的時(shí)候會(huì)變得很大,并且在你刪除數(shù)據(jù)的時(shí)候,文件也不減小。今天就碰到了一次,導(dǎo)致所有的/var分區(qū)都被占用光了。
下面是處理超大ibddata1文件的步驟:
1. 對(duì)每張表使用單獨(dú)的innoDB文件, 修改/etc/my.cnf文件
[mysqld]
innodb_file_per_table
目的很明確,我們可以單獨(dú)刪除每個(gè)文件
2. 導(dǎo)出所有的數(shù)據(jù),重建數(shù)據(jù)庫(kù),然后恢復(fù)數(shù)據(jù):
# /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的每個(gè)數(shù)據(jù)庫(kù)下面,都有會(huì)很多的.ibd文件。這些分散的.ibd文件取代了原來(lái)的那個(gè)ibddata1。
以后刪除數(shù)據(jù)庫(kù)的時(shí)候,直接刪除某個(gè)數(shù)據(jù)庫(kù)的目錄就可以了。
————-華麗的分隔符————-
mysql 使用的引擎:
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 identicalMyISAM 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.
所以不會(huì)直接來(lái)減少ibdata的文件尺寸。
減少ibdata的方法如下
- 1. 用mysqldump等工具導(dǎo)出數(shù)據(jù)
- 2. 停止 mysqld
- 3. 刪除ibdata*, ib_logfile* 文件
- 4. 重新啟動(dòng) mysqld(這時(shí)mysqld就會(huì)自動(dòng)創(chuàng)建 idbdata*, ib_logfile* 文件)
- 5. 將到出來(lái)的數(shù)據(jù)導(dǎo)回去,體積才會(huì)減小。 |