縮短實體遷移到 Amazon Aurora MySQL 的時間 - Amazon Aurora

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

縮短實體遷移到 Amazon Aurora MySQL 的時間

您可以進行以下資料庫修改來加快將資料庫遷移至 Amazon Aurora MySQL 的程序。

重要

請務必對生產資料庫的副本進行這些更新,而不是直接更新生產資料庫。接著您可以備份副本並將它還原至 Aurora MySQL 資料庫叢集,以避免生產資料庫發生任何服務中斷的情況。

不支援的資料表類型

Aurora MySQL 針對資料庫資料表僅支援 InnoDB 引擎。如果您的資料庫中有 MyISAM 資料表,這些資料表必須先轉換,再遷移至 Aurora MySQL。在遷移過程中,轉換程序需要額外的空間將 MyISAM 轉換為 InnoDB。

若要盡可能避免空間不足,或想要加速遷移程序,請先將所有 MyISAM 資料表轉換成 InnoDB 資料表再遷移。產生的 InnoDB 資料表大小相當於 Aurora MySQL 針對該資料表所需的大小。若要將 MyISAM 資料表轉換成 InnoDB,請執行下列命令:

ALTER TABLE schema.table_name engine=innodb, algorithm=copy;

Aurora MySQL 不支援壓縮的資料表或頁面,也就是使用ROW_FORMAT=COMPRESSED或建立的資料表COMPRESSION = {"zlib"|"lz4"}

若要盡可能避免空間不足,或想要加速遷移程序,請將 ROW_FORMAT 設為 DEFAULTCOMPACTDYNAMICREDUNDANT,以展開壓縮資料表。對於壓縮的頁面,請設定COMPRESSION="none"

如需詳細資訊,請參閱 MySQL 文件中的 InnoDB 資料列格式和 InnoDB 資料表和頁面壓縮

您可以在現有的 MySQL 資料庫執行個體上使用下列 SQL 指令碼,以列出資料庫中的 MyISAM 資料表或壓縮資料表。

-- This script examines a MySQL database for conditions that block -- migrating the database into Aurora MySQL. -- It must be run from an account that has read permission for the -- INFORMATION_SCHEMA database. -- Verify that this is a supported version of MySQL. select msg as `==> Checking current version of MySQL.` from ( select 'This script should be run on MySQL version 5.6 or higher. ' + 'Earlier versions are not supported.' as msg, cast(substring_index(version(), '.', 1) as unsigned) * 100 + cast(substring_index(substring_index(version(), '.', 2), '.', -1) as unsigned) as major_minor ) as T where major_minor <> 506; -- List MyISAM and compressed tables. Include the table size. select concat(TABLE_SCHEMA, '.', TABLE_NAME) as `==> MyISAM or Compressed Tables`, round(((data_length + index_length) / 1024 / 1024), 2) "Approx size (MB)" from INFORMATION_SCHEMA.TABLES where ENGINE <> 'InnoDB' and ( -- User tables TABLE_SCHEMA not in ('mysql', 'performance_schema', 'information_schema') or -- Non-standard system tables ( TABLE_SCHEMA = 'mysql' and TABLE_NAME not in ( 'columns_priv', 'db', 'event', 'func', 'general_log', 'help_category', 'help_keyword', 'help_relation', 'help_topic', 'host', 'ndb_binlog_index', 'plugin', 'proc', 'procs_priv', 'proxies_priv', 'servers', 'slow_log', 'tables_priv', 'time_zone', 'time_zone_leap_second', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'user' ) ) ) or ( -- Compressed tables ROW_FORMAT = 'Compressed' );

具有不支援權限的使用者帳戶

具有 Aurora MySQL 不支援之權限的使用者帳戶在匯出時,不支援的權限不會一起匯出。如需支援的權限清單,請參閱 角色型權限模型

您可以在來源資料庫上執行下列 SQL 查詢,以列出具有不支援權限的使用者帳戶。

SELECT user, host FROM mysql.user WHERE Shutdown_priv = 'y' OR File_priv = 'y' OR Super_priv = 'y' OR Create_tablespace_priv = 'y';

Aurora MySQL 第 3 版中的動態權限

不會匯入動態權限。Aurora MySQL 第 3 版支援以下動態權限。

'APPLICATION_PASSWORD_ADMIN', 'CONNECTION_ADMIN', 'REPLICATION_APPLIER', 'ROLE_ADMIN', 'SESSION_VARIABLES_ADMIN', 'SET_USER_ID', 'XA_RECOVER_ADMIN'

以下範例指令碼會將支援的動態權限授予 Aurora MySQL 資料庫叢集中的使用者帳戶。

-- This script finds the user accounts that have Aurora MySQL supported dynamic privileges -- and grants them to corresponding user accounts in the Aurora MySQL DB cluster. /home/ec2-user/opt/mysql/8.0.26/bin/mysql -uusername -pxxxxx -P8026 -h127.0.0.1 -BNe "SELECT CONCAT('GRANT ', GRANTS, ' ON *.* TO ', GRANTEE ,';') AS grant_statement FROM (select GRANTEE, group_concat(privilege_type) AS GRANTS FROM information_schema.user_privileges WHERE privilege_type IN ( 'APPLICATION_PASSWORD_ADMIN', 'CONNECTION_ADMIN', 'REPLICATION_APPLIER', 'ROLE_ADMIN', 'SESSION_VARIABLES_ADMIN', 'SET_USER_ID', 'XA_RECOVER_ADMIN') AND GRANTEE NOT IN (\"'mysql.session'@'localhost'\",\"'mysql.infoschema'@'localhost'\",\"'mysql.sys'@'localhost'\") GROUP BY GRANTEE) AS PRIVGRANTS; " | /home/ec2-user/opt/mysql/8.0.26/bin/mysql -u master_username -p master_password -h DB_cluster_endpoint

使用「rdsadmin'@'localhost」作為 DEFINER 的預存物件

不會匯入使用 'rdsadmin'@'localhost' 作為 DEFINER 的函數、程序、檢視、事件和觸發。

您可以在來源 MySQL 資料庫上使用以下 SQL 指令碼列出具有不支援 DEFINER 的預存物件。

-- This SQL query lists routines with `rdsadmin`@`localhost` as the definer. SELECT ROUTINE_SCHEMA, ROUTINE_NAME FROM information_schema.routines WHERE definer = 'rdsadmin@localhost'; -- This SQL query lists triggers with `rdsadmin`@`localhost` as the definer. SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER FROM information_schema.triggers WHERE DEFINER = 'rdsadmin@localhost'; -- This SQL query lists events with `rdsadmin`@`localhost` as the definer. SELECT EVENT_SCHEMA, EVENT_NAME FROM information_schema.events WHERE DEFINER = 'rdsadmin@localhost'; -- This SQL query lists views with `rdsadmin`@`localhost` as the definer. SELECT TABLE_SCHEMA, TABLE_NAME FROM information_schema.views WHERE DEFINER = 'rdsadmin@localhost';