Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Replication user

Tags:

mysql

I currently have got 2 servers running mysql 5.1. Im settings them up as a master slave. Both have a static ip address and are not part of any domain. (currently they are in a vmware LAN)

The question is as in the mysql documentation it states that u have to setup a domain user for the replication although i dont have a domain.

How will i be able to setup a user so i can let the 2 servers replicate? This is the original line from the documentation:

CREATE USER 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';
like image 262
DW24da Avatar asked Jan 17 '23 09:01

DW24da


1 Answers

Assume the following

SERVER1  (192.168.0.100)
SERVER2  (192.168.0.200)

If you are replicating, then SERVER1 will need to be able to access MySQL on SERVER2 (and potentially vica versa, if SERVER2 needs access to SERVER1). To do this you will need a USER that is permitted to access from the other server, i.e

-- User on SERVER1 that SERVER2 would use to repllicate
CREATE USER 'repl'@'192.168.0.200' IDENTIFIED BY 'slavepass';

-- User on SERVER2 that SERVER1 would use to repllicate
CREATE USER 'rep2'@'192.168.0.100' IDENTIFIED BY 'slavepass';

For purposes of ease of use, you may wish to later on map these to a domain name, i.e.

SERVER1  (192.168.0.100)  server1.mydomain.com
SERVER2  (192.168.0.200)  server2.mydomain.com

And then for sake of consistency you could just have the following user on both SERVER1 and SERVER2

-- User on SERVER1 that SERVER2 would use to repllicate
CREATE USER 'rep'@'%.mydomain.com' IDENTIFIED BY 'slavepass';

-- User on SERVER2 that SERVER1 would use to repllicate
CREATE USER 'rep'@'%.mydomain.com' IDENTIFIED BY 'slavepass';

The domain doesn't even need to be real, as long as the physical servers are able to resolve them, i.e. you could add the following into the hosts files.

-- On SERVER1 add the following into /etc/hosts
server2.mydomain.com    192.168.0.200

-- On SERVER2 add the following into /etc/hosts
server1.mydomain.com    192.168.0.100

If your server is Windows-based, you'll probably find hosts at C:\Windows\system32\drivers\etc\hosts

like image 191
Simon at My School Portal Avatar answered Jan 20 '23 16:01

Simon at My School Portal