[MySQL]表在线重定义-pt-online-schema-change_MySQL
bitsCN.com
MySQL不像Oracle本身就支持表的在线重定义,但我们可以通过开源软件percona-toolkit中的工具pt-online-schema-change进行在线重定义。
官方文档:http://www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html#pt-online-schema-change
pt-online-schema-change包含在percona-toolkit中,所以我们得先下载安装:
wget percona.com/get/percona-toolkit.tar.gztar -zxvf percona-toolkit-2.2.6.tar.gz
好了,安装完成之后,就可以利用该工具进行在线重定义了。主要用到两个参数:
--dry-runCreate and alter the new table, but do not create triggers, copy data, or replace the original table.--executeIndicate that you have read the documentation and want to alter the table. You must specify this option to alter the table. If you do not, then the tool will only perform some safety checks and exit. This helps ensure that you have read the documentation and understand how to use this tool. If you have not read the documentation, then do not specify this option.
首先,我们用--dry-run验证是否可以执行修改:
pt-online-schema-change --alter "modify treatment_afterday INT(4) NULL" D=portal,t=comment_expert -uroot -p*** --dry-runOperation, tries, wait: copy_rows, 10, 0.25 create_triggers, 10, 1 drop_triggers, 10, 1 swap_tables, 10, 1 update_foreign_keys, 10, 1Starting a dry run. `portal`.`comment_expert` will not be altered. Specify --execute instead of --dry-run to alter the table.Creating new table...Created new table portal._comment_expert_new OK.Altering new table...Altered `portal`.`_comment_expert_new` OK.Not creating triggers because this is a dry run.Not copying rows because this is a dry run.Not swapping tables because this is a dry run.Not dropping old table because this is a dry run.Not dropping triggers because this is a dry run.2014-01-14T13:59:08 Dropping new table...2014-01-14T13:59:08 Dropped new table OK.
确认无误之后,再用--execute真正执行:
pt-online-schema-change --alter "modify treatment_afterday INT(4) NULL" D=portal,t=comment_expert -uroot -pzhujie1986 --executeFound 1 slaves: lx203Will check slave lag on: lx203Operation, tries, wait: copy_rows, 10, 0.25 create_triggers, 10, 1 drop_triggers, 10, 1 swap_tables, 10, 1 update_foreign_keys, 10, 1Altering `portal`.`comment_expert`...Creating new table...Created new table portal._comment_expert_new OK.Altering new table...Altered `portal`.`_comment_expert_new` OK.2014-01-14T13:59:20 Creating triggers...2014-01-14T13:59:20 Created triggers OK.2014-01-14T13:59:20 Copying approximately 1165430 rows...Copying `portal`.`comment_expert`: 19% 02:03 remainCopying `portal`.`comment_expert`: 38% 01:37 remainCopying `portal`.`comment_expert`: 55% 01:12 remainCopying `portal`.`comment_expert`: 73% 00:44 remainCopying `portal`.`comment_expert`: 90% 00:15 remain2014-01-14T14:02:08 Copied rows OK.2014-01-14T14:02:08 Swapping tables...2014-01-14T14:02:08 Swapped original and new tables OK.2014-01-14T14:02:08 Dropping old table...2014-01-14T14:02:10 Dropped old table `portal`.`_comment_expert_old` OK.2014-01-14T14:02:10 Dropping triggers...2014-01-14T14:02:10 Dropped triggers OK.Successfully altered `portal`.`comment_expert`.

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

Oracle 資料庫啟動順序為:1. 檢查前置條件;2. 啟動監聽器;3. 啟動資料庫執行個體;4. 等待資料庫開啟;5. 連線至資料庫;6. 驗證資料庫狀態;7.啟用服務(如果需要);8. 測試連接。

Oracle 資料庫日誌的保留期限取決於日誌類型和配置,包括:重做日誌:由 "LOG_ARCHIVE_DEST" 參數配置的最大大小決定。歸檔重做日誌:由 "DB_RECOVERY_FILE_DEST_SIZE" 參數配置的最大大小決定。線上重做日誌:不歸檔,在資料庫重新啟動時遺失,保留期限與實例運行時間一致。稽核日誌:由 "AUDIT_TRAIL" 參數配置,預設保留 30 天。

Oracle 所需記憶體量取決於資料庫大小、活動等級和所需效能等級:用於儲存資料緩衝區、索引緩衝區、執行 SQL 語句和管理資料字典快取。具體數量受資料庫大小、活動水準和所需效能水準影響。最佳實踐包括設定適當的 SGA 大小、調整 SGA 元件大小、使用 AMM 和監控記憶體使用情況。

Oracle 可以透過以下步驟讀取 dbf 檔案:建立外部表,引用 dbf 檔案;查詢外部表,檢索資料;將資料匯入 Oracle 表。

Oracle 資料庫伺服器硬體配置需求:處理器:多核心,主頻至少 2.5 GHz,大型資料庫建議超過 32 個核心。記憶體:小型資料庫至少 8GB,中型 16-64GB,大型資料庫或高負載工作負載高達 512GB 或更多。儲存:SSD 或 NVMe 磁碟,RAID 陣列可提高冗餘和效能。網路:高速網路(10GbE 或更高),專用網路卡,低延遲網路。其他:穩定電源、冗餘組件、相容作業系統和軟體、散熱和冷卻系統。

Oracle 資料庫所需記憶體量取決於資料庫大小、工作負載類型和並髮使用者數量。通常建議:小型資料庫:16-32 GB,中型資料庫:32-64 GB,大型資料庫:64 GB 或更多。其他需考慮因素包括資料庫版本、記憶體最佳化選項、虛擬化和最佳實踐(監視記憶體使用量、調整分配)。

若要在 Oracle 中建立每天執行一次的定時任務,需要執行以下三個步驟:建立一個作業。為作業新增一個子作業,並設定其計畫運算式為「INTERVAL 1 DAY」。啟用作業。

Oracle 資料庫的記憶體需求取決於以下因素:資料庫大小、活動使用者數量、同時查詢、啟用的功能和系統硬體配置。確定記憶體需求的步驟包括:確定資料庫大小、估計活動使用者數量、了解並發查詢、考慮啟用的功能和檢查系統硬體配置。
