| | 1 | This page describes the replication of a MySql server database. |
| | 2 | |
| | 3 | = Objectives = |
| | 4 | The database named {{ps1sc}} is present on the host {{neverland}}. We want to replicate it on the host named {{biglefts}}. {{neverland}} will be the master, {{biglefts}} its slave. |
| | 5 | |
| | 6 | = Preliminary = |
| | 7 | The master MySql version is 5.1.41-3ubuntu12.6. |
| | 8 | The slave one is 5.1.37-1ubuntu5.4-log. |
| | 9 | Warning: two mysql installation are present on biglefts. Use the one in /usr/bin, not the one in /usr/local/bin |
| | 10 | |
| | 11 | = Dump and copy = |
| | 12 | {{{ |
| | 13 | shell prompt> mysqldump ps1sc > ps1sc.sql |
| | 14 | shell prompt> mysql |
| | 15 | mysql prompt> create database ps1sc_copy; |
| | 16 | mysql prompt> exit |
| | 17 | shell prompt> cat ps1sc.sql | mysql ps1sc_copy |
| | 18 | }}} |
| | 19 | |
| | 20 | = Set up the master configuration for replication = |
| | 21 | All commands are executed on the master ({{neverland}}) |
| | 22 | Documentation is at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-masterbaseconfig.html |
| | 23 | * Stop the mysql server: {{sudo service mysql stop}} |
| | 24 | * Note: {{ps waux | grep mysqld}} should not show anything (except the grep part maybe) |
| | 25 | * Edit the mysql configuration and add (or uncomment+modify) the {{[mysqld]}} section so that it contains: |
| | 26 | {{{ |
| | 27 | log-bin=/var/log/mysql/mysql-bin.log |
| | 28 | server-id=2010101301 |
| | 29 | }}} |
| | 30 | * Since we are going to use InnoDB, I followed the advice in documentation and added: |
| | 31 | {{{ |
| | 32 | innodb_flush_log_at_trx_commit=1 |
| | 33 | sync_binlog=1 |
| | 34 | }}} |
| | 35 | * Start the mysql server: {{sudo service mysql start}} |
| | 36 | |
| | 37 | = Set up the slave configuration for replication = |
| | 38 | All commands are executed on the slave ({{biglefts}}) |
| | 39 | Documentation is at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-slavebaseconfig.html |
| | 40 | * Stop the mysql server: {{sudo service mysql stop}} |
| | 41 | * Note: {{ps waux | grep mysqld}} should not show anything (except the grep part maybe) |
| | 42 | * Edit the mysql configuration and add (or uncomment+modify) the {{[mysqld]}} section so that it contains: |
| | 43 | {{{ |
| | 44 | server-id=2010101302 |
| | 45 | }}} |
| | 46 | * I also activated binary logging (see the last paragraph in the documentation) |
| | 47 | {{{ |
| | 48 | log-bin=/var/log/mysql/mysql-bin.log |
| | 49 | }}} |
| | 50 | * Start the mysql server: {{sudo service mysql start}} |
| | 51 | |
| | 52 | = Create a User for Replication = |
| | 53 | Documentation is at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-repuser.html |
| | 54 | On the master: |
| | 55 | {{{ |
| | 56 | mysql prompt> CREATE USER 'repl'@'biglefts.ifa.hawaii.edu' IDENTIFIED BY 'biglefts_repl'; |
| | 57 | mysql prompt> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'biglefts.ifa.hawaii.edu'; |
| | 58 | mysql prompt> FLUSH PRIVILEGES; |
| | 59 | mysql prompt> exit |
| | 60 | }}} |
| | 61 | |
| | 62 | + Obtaining the Replication Master Binary Log Coordinates |
| | 63 | Documentation is at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-masterstatus.html |
| | 64 | |
| | 65 | On the master: |
| | 66 | {{{ |
| | 67 | mysql prompt> FLUSH TABLES WITH READ LOCK; |
| | 68 | mysql prompt> SHOW MASTER STATUS; |
| | 69 | +------------------+----------+--------------+------------------+ |
| | 70 | | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |
| | 71 | +------------------+----------+--------------+------------------+ |
| | 72 | | mysql-bin.000001 | 83959 | | | |
| | 73 | +------------------+----------+--------------+------------------+ |
| | 74 | 1 row in set (0.00 sec) |
| | 75 | }}} |
| | 76 | In a '''different''' shell (do not disconnect from mysql client), make a dump of the database: |
| | 77 | {{{ |
| | 78 | shell prompt> mysqldump --master-data ps1sc > ps1sc.db |
| | 79 | }}} |
| | 80 | Then, release the lock: |
| | 81 | {{{ |
| | 82 | mysql prompt> UNLOCK TABLES; |
| | 83 | }}} |
| | 84 | |
| | 85 | = Set up the slave = |
| | 86 | Copy the dump to the slave (with scp, rsync...). Create the database on the slave and ingest the dump: |
| | 87 | {{{ |
| | 88 | mysql prompt> CREATE DATABASE ps1sc; |
| | 89 | }}} |
| | 90 | {{{ |
| | 91 | shell prompt> cat ps1sc.db | mysql ps1sc |
| | 92 | }}} |
| | 93 | Set up the master configuration (on the slave): |
| | 94 | {{{ |
| | 95 | CHANGE MASTER TO MASTER_HOST='neverland.ifa.hawaii.edu', MASTER_USER='repl', MASTER_PASSWORD='biglefts_repl', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=83959; |
| | 96 | }}} |
| | 97 | |
| | 98 | = Enjoy... = |
| | 99 | It might be necessary to tell the slave to ignore some updates: |
| | 100 | /usr/sbin/mysqld --replicate-ignore-table=mysql.user |