MySQL單獨存放資料表空間Innodb_file_per_table

來源:互聯網
上載者:User

標籤:刪除資料庫   service   undo   ice   mys   作用   啟動   end   star   

在mysql中Innodb_file_per_table參數的作用是什麼呢,其實許多的朋友是不知道的,今天我們來看這篇MySQL單獨存放資料表空間Innodb_file_per_table參數詳解之後你就懂了哦。

MySQL可使用多種引擎,當我們選擇使用InnoDB引擎的時候,ibdata1這個檔案會隨著時間的推移變得越來越大,佔據大量的磁碟空間。

那麼,ibdata1裡儲存了哪些東西,為什麼會變得越來越大呢?首先我們確認一下ibdata1的結構,ibdata1是InnoDB的共有資料表空間,預設配置是把全部資料表空間存放到ibdata1中,因此而造成ibdata1檔案無限增長需釋放之說。

MySQL的Innodb_file_per_table參數控製表空間存放方式,通過配置Innodb_file_per_table參數可把全部資料表空間存放到ibdata1的方式改為使用獨享資料表空間將資料表空間分別單獨存放。

下面介紹一下具體的操作。

1) 匯出資料庫中所有資料

# mysqldump -u root -p --all-database > /tmp/all-database.dump

2) 刪除資料庫中資料

# mysql -u root -pmysql> drop database dbname;

3) 停止MySQL

# service mysqld stop

4) 刪除ibdata1檔案

# mv /var/lib/mysql/ibdata1 /tmp# mv /var/lib/mysql/ib_logfile0 /tmp# mv /var/lib/mysql/ib_logfile1 /tmp

5) 配置innodb_file_per_table

# vi /etc/my.cnfinnodb_data_home_dir = /var/lib/mysqlinnodb_data_file_path = ibdata1:1G;ibdata2:200M:autoextendinnodb_file_per_table

 

開啟獨享資料表空間,並指定ibdata1大小為1G,ibdata2大小200M,自動擴張。

6) 啟動MySQL

 

# service mysqld start

 

7) 匯入資料

把剛才匯出來的資料庫,匯入至資料庫。

# mysql -u root -p < /tmp/all-database.dump

 

開啟獨享資料表空間後,並不是說就不需要ibdata1了,因為在ibdata1中還儲存著下面這些資料。

InnoDB表的中繼資料
Buffer
UNDO日誌

MySQL單獨存放資料表空間Innodb_file_per_table

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.