14.7.1 Resizing the InnoDB System Tablespace

This section describes how to increase or decrease the size of the InnoDB system tablespace.
本節描述如何增加或減少InnoDB系統表空間的大小。

Increasing the Size of the InnoDB System Tablespace
增加InnoDB系統表空間的大小
The easiest way to increase the size of the InnoDB system tablespace is to configure it from the beginning to be auto-extending. Specify the autoextend attribute for the last data file in the tablespace definition. Then InnoDB increases the size of that file automatically in 64MB increments when it runs out of space. The increment size can be changed by setting the value of the innodb_autoextend_increment system variable, which is measured in megabytes.
增加InnoDB系統表空間大小的最簡單方法是從一開始就將其配置爲自動擴展。爲表空間定義中的最後一個數據文件指定autoextend屬性。然後InnoDB在空間不足時以64MB爲增量自動增加該文件的大小。增量大小可以通過設置innodb_autoextend_increment系統變量的值來改變,該變量以兆字節爲單位。
You can expand the system tablespace by a defined amount by adding another data file:
您可以通過添加另一個數據文件,以定義的數量擴展系統表空間:

  • Shut down the MySQL server.
  • 關閉mysql服務器
  • If the previous last data file is defined with the keyword autoextend, change its definition to use a fixed size, based on how large it has actually grown. Check the size of the data file, round it down to the closest multiple of 1024 × 1024 bytes (= 1MB), and specify this rounded size explicitly in innodb_data_file_path.
  • 如果先前的最後一個數據文件是使用關鍵字autoextend定義的,請根據其實際生長的大小將其定義更改爲使用固定大小。檢查數據文件的大小,將其舍入到1024×1024字節(= 1MB)的最接近倍數,並在innodb_data_file_path中明確指定該舍入大小。
  • Add a new data file to the end of innodb_data_file_path, optionally making that file auto-extending. Only the last data file in the innodb_data_file_path can be specified as auto-extending.
  • 在innodb_data_file_path末尾添加一個新的數據文件,可以選擇自動擴展該文件。只有innodb_data_file_path中的最後一個數據文件可以指定爲自動擴展。
  • Start the MySQL server again.
  • 重新啓動mysql服務器
    For example, this tablespace has just one auto-extending data file ibdata1:
    例如,這個表空間只有一個自動擴展的數據文件ibdata1:
    innodb_data_home_dir =
    innodb_data_file_path = /ibdata/ibdata1:10M:autoextend
    Suppose that this data file, over time, has grown to 988MB. Here is the configuration line after modifying the original data file to use a fixed size and adding a new auto-extending data file:
    假設這個數據文件隨着時間的推移已經增長到了988MB。 下面是修改原始數據文件以使用固定大小並添加新的自動擴展數據文件後的配置行:
    innodb_data_home_dir =
    innodb_data_file_path = /ibdata/ibdata1:988M;/disk2/ibdata2:50M:autoextend
    When you add a new data file to the system tablespace configuration, make sure that the filename does not refer to an existing file. InnoDB creates and initializes the file when you restart the server.
    將新數據文件添加到系統表空間配置時,請確保文件名不引用現有文件。 InnoDB在重新啓動服務器時創建並初始化文件。

Decreasing the Size of the InnoDB System Tablespace
減小InnoDB系統表空間的大小
You cannot remove a data file from the system tablespace. To decrease the system tablespace size, use this procedure:
不能從系統表空間中刪除數據文件。要減小系統表空間大小,請使用以下步驟:

  • Use mysqldump to dump all your InnoDB tables, including InnoDB tables located in the MySQL database. As of 5.6, there are five InnoDB tables included in the MySQL database:
  • 使用mysqldump轉儲所有InnoDB表,包括位於MySQL數據庫中的InnoDB表。從5.6開始,MySQL數據庫中包含5個InnoDB表:
    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 |
    +---------------------------+

    *Stop the server.

  • 停止服務
  • Remove all the existing tablespace files (.ibd), including the ibdata and ib_log files. Do not forget to remove .ibd files for tables located in the MySQL database.
  • 刪除所有現有的表空間文件(.ibd),包括ibdata和ib_log文件。不要忘記刪除用於MySQL數據庫中的表的.ibd文件。
  • Remove any .frm files for InnoDB tables.
  • 刪除InnoDB表的所有.frm文件。
  • Configure a new tablespace.
  • 配置新表空間
  • Restart the server.
  • 重啓服務器
  • Import the dump files.
  • 導入轉儲文件。
    Note
    If your databases only use the InnoDB engine, it may be simpler to dump all databases, stop the server, remove all databases and InnoDB log files, restart the server, and import the dump files.
    如果您的數據庫僅使用InnoDB引擎,則轉儲所有數據庫,停止服務器,刪除所有數據庫和InnoDB日誌文件,重新啓動服務器以及導入轉儲文件可能會更簡單。

PREV: 14.7 InnoDB Tablespaces. https://blog.51cto.com/itzhoujun/2359831
NEXT: 14.7.2 Changing the Number or Size of InnoDB Redo. https://blog.51cto.com/itzhoujun/2359833

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章