MySQLã®VPã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã¨SPIDERã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã使ã£ã¦ãä»»æã®ãã¼ãã«ãå¥ãã¹ãã®MySQLã«ç°¡åã«ç§»è¡ããã¹ã¯ãªãããæ¸ãã¾ããã
â»ãã ãPRIMARY KEYããããã®ã«éã
VPとSPIDERを使って任意のテーブルを別ホストに移行する — Gistã«ç½®ãã¦ããã¹ã¯ãªãããè½ã¨ãã¦ãã¦å®è¡æ¨©éãä»ä¸ãã¦ããã
wget http://gist.github.com/raw/571569/cb624c24fac767188b4ee9e4925d3f7bfd4dc443/gistfile1.pl -O mygrate_to chmod +x mygrate_to
移è¡å ãã¹ãã«ç©ºã®ãã¼ãã«ãã¤ããã
mysqldump -u kamipo -h old-db-host --opt --no-data old_db table1 table2 table3 | mysql -u kamipo -h new-db-host -v new_db
移è¡å ãã¹ãã®VPã¨SPIDERã使ã£ã¦ç§»è¡å ãã¹ãã«ãã¼ã¿ãã³ãã¼ããã
./mygrate_to --host new-db-host -u kamipo -d new_db table1 table2 table3 | mysql -u kamipo -h old-db-host -v old_db
ã¨ã£ã¦ãç°¡åã§ããï¼
mygrate_toã¯mysqldumpã¿ããã«æ¨æºåºåã«ç§»è¡ç¨ã®SQLãã¯ãã ãã®ã§ããã¡ã¤ã«ã«ä¿åãã¦ãã¼ãã«ãã©ã¡ã¼ã¿ã®èª¿æ´ããã¼ãã£ã·ã§ãã³ã°ãæåã§ç·¨éããã¨ãæåããå ¨é¨èªåã§ç§»è¡ç¨SQLãæ¸ããªãã¦ããã®ã§ä¾¿å©ã ã¨æãã¾ãã
ãã¨æ³¨æãããã®ã¯ãMySQLã®ä»æ§ã§COMMENTã¯60æå以å ã«åãè©°ããããã®ã§ãã¨ãã«VPã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã®ãã¼ãã«ãã©ã¡ã¼ã¿ã¯æåæ°å¶éã«å¼ã£ããããã¡ã§ããã¨ããããçããã¼ãã«åã«ãããªããã¦åé¿ããããç¾ç¶ãªãããã§ãã
ã追è¨ã
VPã¨SPIDERã®ãã¼ãã«ãã©ã¡ã¼ã¿ã¯COMMENTã¨CONNECTIONã®ã©ã¡ãã«ãæ¸ããã®ã§ãæåæ°å¶éã«å¼ã£ããããããªå ´åã¯CONNECTIONãä½µç¨ãããã¨ã§åé¿ã§ãã¾ãã
ã¾ããMySQL 5.5ã§ã¯COMMENTã®æåæ°å¶éãããªãæ¡å¼µããã¦ããããã§ãVPã¨SPIDERã®ãã¼ãã«ãã©ã¡ã¼ã¿ãæå®ããç¨åº¦ã§ã¯å°ããªãããã«ãªã£ã¦ããã¯ãã§ãã