2016-12-05 53 views
0

所以我需要做此表的變化變化表結構和數據遷移MYSQL只查詢

assignments 
- id 
- organisation_id (fkey to organisations.id) 

organisations 
- id 

contacts 
- id 
- assignment_id (fkey to assignment.id) 

assignments // Not altered 
- id 
- organisation_id 

organisations // Not altered 
- id 

contacts //Table altered (-assignment_id, +organisation_id) 
- id 
- organisation_id (fkey to organisations.id) 

assignment_contact //New table with 2 foregin keys to existing tables 
- contact_id (fkey to contact.id) 
- assignment_id (fkey to assignment.id) 

所以我想知道如果這種遷移可以用MySQL查詢完成,而不需要做任何手動後處理等等。

「障礙」

  1. 有〜在「聯繫人」 22K記錄表
  2. 它在生產中完成,因此可能沒有任何停機時間超過一兩分鐘

非常感謝您的任何建議或指導。

感謝

+0

是,這種遷移可以做到用mysql查詢mysql的終端。 – Shadow

回答

0

是的,這可以在生產完成沒有問題, 記錄的數量〜22K是MySQL的數據非常低量。

建議是先創建並填充新表。 然後爲您輸入的表創建遷移表,並將它們填充到表中。 然後您只需將生產表與遷移表交換(將現有名稱重命名爲bkp_table_name,將遷移名稱重命名爲實名)。 如果一切正常,那麼你可以刪除bkp_ *表。

當然先做一個備份,並記住表索引。

編輯:另一個建議是使用,而不是MySQL工作臺或phpMyAdmin的唯一