Fully Managed Linux Hosting

Recent Articles

Finding And Using DateFormat Within SQL
Have you ever tried to find a DateFormat or date_format function in SQL Server? Chances are you probably ended up concatenating a bunch of DatePart strings to get the format you are looking for. What about grouping...

MySQL Replication
Replication is a way to run several SQL servers so that all of them have a current copy of a database or databases. Keep in mind that replication is not the same as...

Closing The Open Source Model Of MySQL
Okay, I didn't really want to write about Sun again today, but Simon has an interesting post about the "Sun Model" for open source business. Simon states that the model boils down to: "1. remove barriers to software...

SQL Loyalty And Competition
MySQL's Kaj Arno has an interesting post titled: "On Loyalty, Competition and Underdogs". Kaj starts with his son's list of reasons to stay with Bayern Munchen...

Microsoft Adds New Feature To SQL Server With...
Microsoft has introduced a new managed self-service analysis capabilities code-named "Project Gemini," and self-service reporting in the next release of Microsoft SQL Server focused on Business Intelligence (BI) code...

Emulating LIMIT With MSSQL 2005
I don't like MSSQL, I prefer MySQL, but many times I have to deal with it at work. Lots of developers, including me and my co-worker Enrico, hate that Microsoft...



Click to Play

How Net Neutrality Affects Search..
Although network neutrality is an issue that could affect everyone, it seems that people are either not concerned or simply unaware of its potential. One industry that seems...

12.16.08

Setting Up MySQL Replication

By Jay Fougere

This is the second part of an article that I wrote discussing replication in MySQL. The first part of the article was a more general primer on what replication is and how it differs from clustering. The first part of the article can be found here.

Today we will discuss actually setting up replication with MySQL. I am assuming you are using a Unix based system such as Linux, OpenSolaris or one of the BSDs. I am also assuming you already have MySQL (server and client tools) installed on your machine; installing MySQL is a bit beyond the scope of this article. The official MySQL documentation can be found here for versions 5.0.X and for versions 5.1.X.

1). Creating a user

You will need to create a user on each master server you have that will have permissions to the database(s) that you will be replicating. I have only ever set up replication with machines on the same rack (usally even sharing the same network switch), thus I have always assigned IP addresses to these machines on a private network. I do this mainly for security reasons. First of all, using a private network adds a hurdle to any potential hackers; they cannot directly access MySQL via the network. Secondly, this makes for easier firewalling of the database machines. Anyway, log in to mysql and create the user and give that user permissions to the databases that will be replicated:

#mysql -u root -p

mysql> GRANT REPLICATION SLAVE ON database1.* TO 'slave'@'192.168.1.%' IDENTIFIED BY 'mypassword';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT REPLICATION SLAVE ON database2.* TO 'slave'@'192.168.1.%' IDENTIFIED BY 'mypassword';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)


Fully Managed Linux Hosting

The previous 3 statements will grant all permissions on database1 and database2 to user cluster on the network 192.168.1.0/24 with password "mypassword". You may want to be more creative with your naming :)

Also, a quick note on using IP addresses. You can use host names for your connections amongst MySQL servers, however this can introduce latency and another level of management should DNS or whatever name service you use become unreachable. Considering this, it is simpler and more reliable to simply use IP addresses rather than rely on external name services.

2). Assigning each server a unique ID

After creating a user for replication, you will need to assign each server in the replication chain a unique server ID number. This number is arbitrary, but must be unique for each server. I tend to use numbers in powers of 10. In other words the first server would be 10, the second, 20 etc... To assign the server number, simply add a line like the following to your my.cnf (usually located in either /etc/ or /usr/local/etc depending on the location of your MySQL installation) on each server:

server-id=10

3). Set up binary logging on the master server(s)

Next, you will need to do is set up binary logging on the master server. If you are going to use multi-master replication, you will need to set up binary logging on each server that will act as a master.

Continue reading this article.


About the Author:
Jay Fougere is the IT manager for the iEntry network. He also writes occasional articles. If you have any IT questions, please direct them to Jay@ientry.com.
SQLproNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
SQLproNews.com WirelessProNews.com
CProgrammingTrends.com SysAdminNews.com


About SQLproNews
SQLproNews is a collection of up to date tutorials and insightful articles designed to help SQL users of any skill level implement successful SQL systems and practices. SQL Strategies and Tactics for Business




-- SQLProNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2008 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

advertising info | news headlines | free newsletters | comments/feedback | submit article


SQL Strategies and Tactics for Business SQLproNews News Archives About Us Feedback SQLproNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact