I’m playing with the latest 5.1.11 beta in a master/slave replication situation. Given a lack of H/W lying around I’m configuring a mixed H/W setup to leverage an existing office’s after hours CPUs running Windows XP for my slaves. So here is my test setup.
Server
Linux – 192.168.100.170
The following are the relevent my.cnf settings
[mysqld] port=3307 server-id = 1 log-bin=mysql-bin
Confirming the server. I did some test commands prior to confirm the position.
$ mysql -uroot -p mysql Your MySQL connection id is 47 to server version: 5.1.11-beta-log mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 1759 | | | +------------------+----------+--------------+------------------+
Slave
Windows XP – 192.168.100.171
The following are the relevent my.cnf settings
server-id = 11 master-host = 192.168.100.170 master-user = rep master-password = dolphin master-port = 3307
Test
I’ve taken a few steps back for the documentation, to clearly identify any setup problems for those that are also reviewing this to setup replication.
Starting the Slave, I get the following error.
060720 16:36:22 [ERROR] Slave I/O thread: error connecting to master 'root@192.168.100.170:3307': Error: 'Host '192.168.100.171' is not allowed to connect to this MySQL server' errno: 1130 retry-time: 60 retries: 86400
Makes sense, you need to give access to the slave to access the master. So to the uninitiated you may miss that a slave requires different access then a default ‘all’ for example.
On the master.
$ mysql -uroot -p mysql mysql> grant replication slave on *.* to rep@'192.168.100.%' identified by 'dolphin';
Just a side note, when defining the master replication you can specifically state databases to include or ignore, but to set up the appropiate grant on a particular database fails. For example:
mysql> grant replication slave on test.* to rep@'192.168.100.%' identified by 'dolphin'; ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
But the problem was not indeed here, looking closer at the error message, the host and the port matched the my.cnf file, but the user didn’t. It was ‘root’ when it should have been ‘rep’.
So, some advice later from the Planet MySQL #IRC (thanks Sheeri) you find if you RTFM at MySQL 5.1 Manual – Replication Startup Options .
So investigating the master.info file located in the slave data directory I get:
14 mysql-bin.000001 1839 192.168.100.170 root dolphin 3307 60 0
There is a mismatch between the master.info file and the my.cnf file. I don’t recall the exact series of events when I setup the Windows XP installation, I know I first tested it as a master, and it’s most likely I then configured the slave settings, but used a master-user of ‘root’ initially and started the server. Then thinking this was insecure before I’d created the permissions, I changed the my.cnf file to use the user ‘rep’.
So the lessons today are:
- Correctly configure your slave settings before starting the mysql server for the first time.
- MySQL records slave replication authentication information in two files, the my.cnf and the master.info.
- Making changes to my.cnf are not reflected in an existing master.info. In this situtation use the CHANGE MASTER TO command in addition.
- Read the Manual. MySQL does have good documentation, and when it’s not quite right, like I found yesterday with Bug #21134, report it to help everybody in the future.
Now I fully agree this is a Replication 101 error. My excuse is the last replication I setup was in 2003 under 3.23, and it worked perfectly well in a production system for 2 years with a number of 3.23 and 4.0 slaves. Hence while I’m just refreshing my replication skills now.