Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. ----- ALL TABLES MUST BE INNODB -- IF NOT REPLICA FAILS!!!
  2.  
  3. - file_per_table = 1
  4.  
  5. - convert to innodb
  6.  
  7. for DB in $(mysql -u root -e "show databases;" | grep -v "Database")
  8. do
  9. echo $DB
  10. mysql -u root $DB -e "show table status where Engine='MyISAM';" | awk 'NR>1 {print "ALTER TABLE "$1" ENGINE = InnoDB;"}' | mysql -u root $DB
  11. echo "Sleeping"
  12. sleep 1
  13. done
  14.  
  15.  
  16. - optimize tables
  17. mysqlcheck -o --all-databases
  18.  
  19. - make sure tmp is big enough
  20. - innodb_log is big enough
  21.  
  22. - restart mysql service after convert and optimize
  23.  
  24.  
  25.  
  26. Make sure we have ID on master my.cnf:
  27.  
  28. log_bin = binlog
  29. binlog_format=row
  30. bind-address = 0.0.0.0
  31. expire-logs-days=3
  32. server-id = 501
  33.  
  34. On the slave my.cnf:
  35.  
  36. server_id=1001
  37.  
  38. Create replica users on master:
  39. CREATE USER 'replicausr'@'%' IDENTIFIED BY 'my_supper_secret_password';
  40. GRANT ALL PRIVILEGES ON *.* TO 'replicausr'@'%' IDENTIFIED BY 'my_supper_secret_password' WITH GRANT OPTION;
  41.  
  42. if you have just one IP you access it from :
  43. CREATE USER replicausr@8.29.134.10 IDENTIFIED BY 'my_supper_secret_password';
  44. GRANT ALL PRIVILEGES ON *.* TO replicausr@8.29.134.10 IDENTIFIED BY 'my_supper_secret_password' WITH GRANT OPTION;
  45.  
  46. We can either use xtrabackup or manual procedure:
  47. (for xtrabackup option keep in mind to have clocks synced )
  48.  
  49. Manual method:
  50.  
  51. on master:
  52.  
  53. FLUSH TABLES WITH READ LOCK;
  54.  
  55. SHOW MASTER STATUS;
  56. take note of the Poisition field and the file
  57.  
  58. MariaDB [(none)]> SHOW MASTER STATUS;
  59. +---------------+----------+--------------+------------------+
  60. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  61. +---------------+----------+--------------+------------------+
  62. | binlog.000001 | 72894029 | adclk_imobi_tmp,mgd |
  63. |+---------------+----------+--------------+------------------+
  64.  
  65. We do the dump:
  66.  
  67. cd /backups/
  68. time mysqldump --all-databases --single-transaction --quick --lock-tables=false > alles.sql
  69.  
  70. We unlock the tables:
  71. UNLOCK TABLES;
  72.  
  73. open SCREEN and into screen
  74. scp alles.sql root@ip:/backup/
  75.  
  76. On the slave:
  77. time mysql -ureplicausr -pmy_supper_secret_password < alles.sql
  78.  
  79.  
  80. STOP SLAVE;
  81.  
  82. CHANGE MASTER TO MASTER_HOST='IP_OF_MASTER',
  83. MASTER_USER='replicausr',
  84. MASTER_PASSWORD='my_supper_secret_password',
  85. MASTER_PORT=3306,
  86. MASTER_LOG_FILE='binlog.00_FILE_WE_TOOK_NOTE_EARLIER__',
  87. MASTER_CONNECT_RETRY=10,
  88. MASTER_LOG_POS=__POISTION_WE_TOOK_NOTE_EARLIER__;
  89.  
  90.  
  91. START SLAVE;
  92. SHOW SLAVE STATUS \G;
  93.  
  94. # in case of a few rows might have gotten behind we can just skip the duplicates by doing:
  95. STOP SLAVE; SET GLOBAL SQL_SLAVE_SKIP_COUNTER=100; START SLAVE;
  96.  
  97. after everything is synced:
  98.  
  99. we just do this on the slave:
  100.  
  101. STOP SLAVE;
  102. RESET MASTER;
  103. Optional: CHANGE MASTER TO MASTER_HOST='';
  104.  
  105. and change the application pointer to the slave
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement