MySQL 減少InnoDB系統表空間的大小
減少InnoDB系統表空間的大小
不能從系統表空間中刪除資料檔案。若要減少系統表空間大小,請使用此過程:
1.使用mysqldump將所有的包括MySQL資料庫中的InnoDB表dump出來,在5.6當前版本中,包括5張InnoDB表:
[mysql@localhost ~]$ mysql -uroot -pxxzx7817600 mysql mysql: [Warning] Using a password on the command line interface can be insecure. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.26-log Source distribution Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like 'innodb_data%'; +-----------------------+------------------------------------+ | Variable_name | Value | +-----------------------+------------------------------------+ | innodb_data_file_path | ibdata1:76M;ibdata2:50M:autoextend | | innodb_data_home_dir | | +-----------------------+------------------------------------+ 2 rows in set (0.01 sec) mysql> SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='mysql' and ENGINE='InnoDB'; +---------------------------+ | TABLE_NAME | +---------------------------+ | engine_cost | | gtid_executed | | help_category | | help_keyword | | help_relation | | help_topic | | innodb_index_stats | | innodb_table_stats | | plugin | | server_cost | | servers | | slave_master_info | | slave_relay_log_info | | slave_worker_info | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | +---------------------------+ 19 rows in set (0.00 sec) [mysql@localhost ~]$ mysqldump -uroot -pxxzx7817600 --all-databases > all_db_dump_20220223.sql mysqldump: [Warning] Using a password on the command line interface can be insecure.
2.停止MySQL伺服器
[mysql@localhost ~]$ mysqladmin -uroot -pxxzx7817600 shutdown mysqladmin: [Warning] Using a password on the command line interface can be insecure.
3.刪除所有已經存在的表空間檔案(*.ibd),包括ibdata和ib_log檔案。不要忘記刪除MySQL資料庫中的*.ibd檔案。
[mysql@localhost mysql]$ find ./mysql -name "*.ibd" ./mysql/plugin.ibd ./mysql/servers.ibd ./mysql/help_topic.ibd ./mysql/help_category.ibd ./mysql/help_relation.ibd ./mysql/help_keyword.ibd ./mysql/time_zone_name.ibd ./mysql/time_zone.ibd ./mysql/time_zone_transition.ibd ./mysql/time_zone_transition_type.ibd ./mysql/time_zone_leap_second.ibd ./mysql/innodb_table_stats.ibd ./mysql/innodb_index_stats.ibd ./mysql/slave_relay_log_info.ibd ./mysql/slave_master_info.ibd ./mysql/slave_worker_info.ibd ./mysql/gtid_executed.ibd ./mysql/server_cost.ibd ./mysql/engine_cost.ibd [mysql@localhost mysql]$ find ./mysql -name "*.ibd" | xargs -n 1 rm -f [mysql@localhost mysql]$ rm -rf ibdata* [mysql@localhost mysql]$ rm -rf ib_log* [mysql@localhost mysql]$ ls -lrt ibdata* ls: 無法訪問ibdata*: 沒有那個檔案或目錄 [mysql@localhost mysql]$ ls -lrt ib_log* ls: 無法訪問ib_log*: 沒有那個檔案或目錄
4.刪除InnoDB表的.frm檔案
[mysql@localhost mysql]$ rm -rf mysql/plugin..frm [mysql@localhost mysql]$ rm -rf mysql/servers..frm [mysql@localhost mysql]$ rm -rf mysql/help_topic..frm [mysql@localhost mysql]$ rm -rf mysql/help_category..frm [mysql@localhost mysql]$ rm -rf mysql/help_relation.frm [mysql@localhost mysql]$ rm -rf mysql/help_keyword.frm [mysql@localhost mysql]$ rm -rf mysql/time_zone_name.frm [mysql@localhost mysql]$ rm -rf mysql/time_zone.frm [mysql@localhost mysql]$ rm -rf mysql/time_zone_transition.frm [mysql@localhost mysql]$ rm -rf mysql/time_zone_transition_type.frm [mysql@localhost mysql]$ rm -rf mysql/time_zone_leap_second.frm [mysql@localhost mysql]$ rm -rf mysql/innodb_table_stats.frm [mysql@localhost mysql]$ rm -rf mysql/innodb_index_stats.frm [mysql@localhost mysql]$ rm -rf mysql/slave_relay_log_info.frm [mysql@localhost mysql]$ rm -rf mysql/slave_master_info.frm [mysql@localhost mysql]$ rm -rf mysql/slave_worker_info.frm [mysql@localhost mysql]$ rm -rf mysql/gtid_executed.frm [mysql@localhost mysql]$ rm -rf mysql/server_cost.frm [mysql@localhost mysql]$ rm -rf mysql/engine_cost.frm
5.配置一個新表空間
[mysql@localhost mysql]$ vi my.cnf ....... innodb_data_file_path = ibdata1:10M:autoextend
6.重啟MySQL伺服器
[root@localhost ~]# service mysqld start Starting MySQL......... SUCCESS!
7.匯入dump檔案
[mysql@localhost ~]$ mysql -uroot -pxxzx7817600 < all_db_dump_20220223.sql mysql: [Warning] Using a password on the command line interface can be insecure. [mysql@localhost ~]$ mysql -uroot -pxxzx7817600 mysql mysql: [Warning] Using a password on the command line interface can be insecure. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.26-log Source distribution Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like 'innodb_data%'; +-----------------------+------------------------+ | Variable_name | Value | +-----------------------+------------------------+ | innodb_data_file_path | ibdata1:10M:autoextend | | innodb_data_home_dir | | +-----------------------+------------------------+ 2 rows in set (0.01 sec)
InnoDB系統表空間的檔案變回原來的ibdata1了
mysql> SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='mysql' and ENGINE='InnoDB'; +---------------------------+ | TABLE_NAME | +---------------------------+ | engine_cost | | gtid_executed | | help_category | | help_keyword | | help_relation | | help_topic | | innodb_index_stats | | innodb_table_stats | | plugin | | server_cost | | servers | | slave_master_info | | slave_relay_log_info | | slave_worker_info | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | +---------------------------+ 19 rows in set (0.01 sec)
注意:如果您的資料庫只使用InnoDB引擎,那麼可能更簡單的方法是轉儲所有資料庫,停止伺服器,刪除所有資料庫和InnoDB日誌檔案,重新啟動伺服器,並匯入轉儲檔案。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2871764/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 增加InnoDB系統表空間大小MySql
- MySQL InnoDB系統表空間資料檔案配置MySql
- MySQL InnoDB表空間加密MySql加密
- MySQL InnoDB Undo表空間配置MySql
- MySQL InnoDB臨時表空間配置MySql
- MySQL InnoDB File-Per-Table表空間MySql
- Configure innodb 表空間
- MySQL innodb表使用表空間物理檔案複製表MySql
- MySQL 系統表空間檔案解析MySql
- Innodb:Undo 表空間巨大
- 更改undo表空間大小
- 減少Android APK的大小99.99%AndroidAPK
- innodb表空間儲存結構
- mysql Innodb表空間解除安裝、遷移、裝載的使用方法MySql
- win10系統怎麼優化字型庫減少c盤空間佔用Win10優化
- 深圳眾創空間,減少不必要成本
- 為Zabbix MySQL設定獨立表空間innodb_file_per_tableMySql
- win10系統怎麼最佳化字型庫減少c盤空間佔用Win10
- 如何獲取 PostgreSQL 資料庫中的表大小、資料庫大小、索引大小、模式大小、表空間大小、列大小SQL資料庫索引模式
- MySQL 傳輸表空間MySql
- MySQL InnoDB頁面大小配置MySql
- MySQL 中的共享表空間與獨立表空間如何選擇MySql
- 【譯】如何使用webpack減少vuejs打包的大小WebVueJS
- MySQL實現當前資料表的所有時間都增加或減少指定的時間間隔(推薦)MySql
- mysql之 表空間傳輸MySql
- mysql收縮共享表空間MySql
- mysql關於表空間的總結MySql
- Mysql InnoDB刪除資料後釋放磁碟空間的方法MySql
- 達夢資料庫表空間等空間大小查詢方法總結資料庫
- [20190124]系統表空間塊ITL的LCK.txt
- SQL Server檢視所有表大小,所佔空間SQLServer
- VMware載入的Ubuntu系統提示空間不足,使用 GParted調整大小。Ubuntu
- 12c – 使用跨平臺增量備份來減少傳輸表空間的停機時間 (Doc ID 2102859.1)
- 12c – 使用跨平臺增量備份來減少傳輸表空間的停機時間 (文件 ID 2102859.1)
- MySQL 遷移表空間,備份單表MySql
- 談談什麼是MySQL的表空間?MySql
- [轉帖]達夢資料庫-統計資料表資料量及空間表大小資料庫
- mysql臨時表,臨時表空間,ibtmp1表空間暴增原因初探MySql