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.

Oct 11, 2011

MySQL: Relocating Slave Logs

On a master-slave configuration, MySQL creates binary logs on the master and events recorded in these files are read by the slave and stores them in relay logs. These log files are stored in the data directory by default. However, they can be relocated to another location for optimization purposes. 

We have a master-slave configuration set up on Linux and there was a need to move the log files to its own directory. With all the writing that MySQL is doing, it is best practice to move these log files out of the data directory. These are the files that I modified/copied/moved: 
  •     <host-name>-relay-bin.XXXXXX
  •     <host-name>-relay-bin.index
  •     relay-log.info 
These files are in the data directory and we would like to move the <host-name>-relay-bin.* files to /var/log/mysql directory. These are the steps that I did:
1. Shutdown the slave. On my test bed, I ran the mysql.server command which comes with the MySQL installer.

shell> mysql.server stop

2. Add the following to your config file under the mysqld section, which is /etc/my.cnf. You might need root access to do this. My slave server name is server02.

relay-log=/var/log/mysql/server02-relay-bin

3. Move the relay files to the new location. My data directory is /var/lib/mysql.

shell> mv /var/lib/mysql/server02-relay-bin.* /var/log/mysql

4. Modify the entries in the /var/lib/mysql/relay-log.info to reflect the new directory. For example, the contents of my relay-log.info are:

./server02-relay-bin.000011
67884
server01-bin.000023
67735
9

All I did was change the first line to /var/log/mysql/server02-relay-bin.000011.

/var/log/mysql/server02-relay-bin.000011
67884
server01-bin.000023
67735
9

5. Modify the entries in the /var/log/mysql/server02-relay-bin.index (remember we've already moved these files). For example, if the contents of the server02-relay-bin.index are:

./server02-relay-bin.000010
./server02-relay-bin.000011

All I did was to change the (.) with /var/log/mysql:

/var/log/mysql/server02-relay-bin.000010
/var/log/mysql/server02-relay-bin.000011

6. Start the slave

shell> mysql.server start

At this point, the relay log files have been moved to the new location. Create a test table on the master and see if it replicates to the slave.

No comments:

Post a Comment