首頁 資料庫 mysql教程 [MySQL]表在线重定义-pt-online-schema-change_MySQL

[MySQL]表在线重定义-pt-online-schema-change_MySQL

May 27, 2016 pm 02:12 PM
oracle 網路 開源軟體

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
登入後複製
通过上诉步骤之后,把./percona-toolkit-2.2.6/bin下的可执行文件加入到$PATH中即可。

好了,安装完成之后,就可以利用该工具进行在线重定义了。主要用到两个参数:

--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`.
登入後複製
除了修改表结构之外,在大表上建索引也可以利用这种方法防止锁表。 bitsCN.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

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

oracle資料庫啟動步驟順序為 oracle資料庫啟動步驟順序為 May 10, 2024 am 01:48 AM

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

oracle資料庫日誌會保存多久 oracle資料庫日誌會保存多久 May 10, 2024 am 03:27 AM

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

oracle需要多少內存 oracle需要多少內存 May 10, 2024 am 04:12 AM

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

oracle怎麼讀取dbf文件 oracle怎麼讀取dbf文件 May 10, 2024 am 01:27 AM

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

oracle資料庫伺服器硬體配置需求 oracle資料庫伺服器硬體配置需求 May 10, 2024 am 04:00 AM

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

用oracle資料庫需要多大內存 用oracle資料庫需要多大內存 May 10, 2024 am 03:42 AM

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

oracle定時任務每天都會執行一次建立步驟 oracle定時任務每天都會執行一次建立步驟 May 10, 2024 am 03:03 AM

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

oracle資料庫需要多大內存 oracle資料庫需要多大內存 May 10, 2024 am 02:09 AM

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

See all articles