IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changes between Initial Version and Version 1 of MySqlReplication


Ignore:
Timestamp:
Oct 13, 2010, 3:03:04 PM (16 years ago)
Author:
Serge CHASTEL
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MySqlReplication

    v1 v1  
     1This page describes the replication of a MySql server database.
     2
     3= Objectives =
     4The 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 =
     7The master MySql version is 5.1.41-3ubuntu12.6.
     8The slave one is 5.1.37-1ubuntu5.4-log.
     9Warning: 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{{{
     13shell prompt> mysqldump ps1sc > ps1sc.sql
     14shell prompt> mysql
     15  mysql prompt> create database ps1sc_copy;
     16  mysql prompt> exit
     17shell prompt> cat ps1sc.sql | mysql ps1sc_copy
     18}}}
     19
     20= Set up the master configuration for replication =
     21All commands are executed on the master ({{neverland}})
     22Documentation 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{{{
     27log-bin=/var/log/mysql/mysql-bin.log
     28server-id=2010101301
     29}}}
     30* Since we are going to use InnoDB, I followed the advice in documentation and added:
     31{{{
     32innodb_flush_log_at_trx_commit=1
     33sync_binlog=1
     34}}}
     35* Start the mysql server: {{sudo service mysql start}}
     36
     37= Set up the slave configuration for replication =
     38All commands are executed on the slave ({{biglefts}})
     39Documentation 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{{{
     44server-id=2010101302
     45}}}
     46* I also activated binary logging (see the last paragraph in the documentation)
     47{{{
     48log-bin=/var/log/mysql/mysql-bin.log
     49}}}
     50* Start the mysql server: {{sudo service mysql start}}
     51
     52= Create a User for Replication =
     53Documentation is at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-repuser.html
     54On 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
     63Documentation is at http://dev.mysql.com/doc/refman/5.1/en/replication-howto-masterstatus.html
     64
     65On 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+------------------+----------+--------------+------------------+
     741 row in set (0.00 sec)
     75}}}
     76In a '''different''' shell (do not disconnect from mysql client), make a dump of the database:
     77{{{
     78shell prompt> mysqldump --master-data ps1sc > ps1sc.db
     79}}}
     80Then, release the lock:
     81{{{
     82  mysql prompt> UNLOCK TABLES;
     83}}}
     84
     85= Set up the slave =
     86Copy the dump to the slave (with scp, rsync...). Create the database on the slave and ingest the dump:
     87{{{
     88mysql prompt> CREATE DATABASE ps1sc;
     89}}}
     90{{{
     91shell prompt> cat ps1sc.db | mysql ps1sc
     92}}}
     93Set up the master configuration (on the slave):
     94{{{
     95CHANGE 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... =
     99It might be necessary to tell the slave to ignore some updates:
     100/usr/sbin/mysqld --replicate-ignore-table=mysql.user