WELCOME!

What is Pinoy? It's a slang for Filipino, a person who comes from the Republic of the Philippines, or commonly known as the Philippine Islands (PI). I am a Filipino and works as an Oracle DBA in the United States. Whenever an issue arises or just for experiments, I usually forget what I did to solve/conduct them. There must be a central location where I can put everything. Thus, this blog was born. It's a collection of ideas, tips and tricks, scripts, or anything interesting that happened to me on an Oracle database or any other stuff.

The simpler, the better! has always been my motto. You don't have to complicate things. Simple things, for me, is always easier, just like my site.

FYI, anything that is written here is based on my personal experiences and is not endorsed by any other party. Also, I will not be held liable for issues that can arise by following whatever I did. Just like any other good DBA would say... ALWAYS TEST!

Hope you can find this site helpful in whatever you need and remember, I am not a guru.

May 18, 2011

MySQL: Setting-up replication

I was given the task to set-up replication on our MySQL database. However, I am still a newbie with this database but I was able to complete the task. Here's what I did:

1. Modified the my.ini to include the following under the mysqld section:

[mysqld]
log-bin=mysql-bin
server-id=11

2. Created a replication user on the database. Let's call this the master.

mysql> create user 'repladm'@'%.domain.com' identified by 'replpassword';
mysql> grant replication slave on *.* to 'repladm'@'%.domain.com';

3. Obtained the replication coordinates from the master.

mysql> flush tables with read lock;
mysql> show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| info-mysql.000015 |  8177182 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Take note of the position and the file values.

4. Stopped MySQL on the master and slave.
5. Copied the data directory over to the slave machine.
6. Modified the my.ini file on the slave with the following under the mysqld section:

[mysqld]
server-id=12

7. Started MySQL on the master.
8. Started MySQL on the slave.
9. Set the master configuration on the slave.

mysql> CHANGE MASTER TO
    -> MASTER_HOST='masterdb.domain.com',
    -> MASTER_USER='repladm',
    -> MASTER_PASSWORD='replpassword',
    -> MASTER_LOG_FILE=' info-mysql.000015',
    -> MASTER_LOG_POS=8177182;

mysql> start slave;

10. Check the status on the master.

mysql> show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| info-mysql.000015 |  8177182 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

11. Check the status on the slave.

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: masterdb.domain.com
                  Master_User: repladm
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: info-mysql.000015
          Read_Master_Log_Pos: 8177182
               Relay_Log_File: masterdb2-relay-bin.000051
                Relay_Log_Pos: 8177329
        Relay_Master_Log_File: info-mysql.000015
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 8177182
              Relay_Log_Space: 8177640
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 22
1 row in set (0.00 sec)

The Read_Master_Log_Pos and Master_Log_File values should be the same as the ones on the master.

No comments:

Post a Comment