Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "could not initailize master info structure" while doing Master Slave Replication in MySQL

I am trying to do Master Slave Replication for MySQL. When i am typing the following command:

CHANGE MASTER TO MASTER_HOST='10.1.100.1', MASTER_USER='slave_user', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=451228; mysql> START SLAVE; 

it throws the following error:

ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log

Any help would be greatly appreciated.

like image 215
user619684 Avatar asked Feb 17 '11 13:02

user619684


People also ask

How do I fix a MySQL error on the slave?

If the error still comes back on the Slave, you will have to run STOP SLAVE; DROP USER 'fetchers'@'localhost' START SLAVE; on the Slave. MySQL 5.7 may have generated a warning on the Master and passed it on the Slave.

What is the default server_id for MySQL replication?

Whenever a query is executed and is recorded in the master's binary log, the server_id of the master is recorded with it. By default, if a server_id is not defined in /etc/my.cnf, the server_id is defaulted to 1. However, the rules MySQL Replication demand that a server_id be explicitly defined in the master's /etc/my.cnf.

How does MySQL replication know it's safe to execute a SQL statement?

In addition, for any given slave, mysqld checks the server_id of the SQL statement as it reads it from the relay log and makes sure it is different from the slave's server_id. That is how MySQL Replication knows it is safe to execute that SQL statement.

What is the difference between replication slave and if usage?

If usage means you can only connect to the DB Server and not anything else. Whereas in this case REPLICATION SLAVE will require to read and pull binlog events from Master. GRANT REPLICATION SLAVE ON *.*


2 Answers

TRY TO RESET IT, IT DOES MAGIC! ON SLAVE THE SLAVE MYSQL COMMAND TYPE:

RESET SLAVE; 

THEN TRY AGAIN:

CHANGE MASTER TO MASTER_HOST='10.1.100.1', MASTER_USER='slave_user', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=451228; mysql> START SLAVE; 
like image 96
Neo Avatar answered Oct 18 '22 04:10

Neo


Please check several things:

1) Make sure the Master's /etc/my.cnf has server_id actually set

Here is why: Replication relies on the server_id. Whenever a query is executed and is recorded in the master's binary log, the server_id of the master is recorded with it. By default, if a server_id is not defined in /etc/my.cnf, the server_id is defaulted to 1. However, the rules MySQL Replication demand that a server_id be explicitly defined in the master's /etc/my.cnf. In addition, for any given slave, mysqld checks the server_id of the SQL statement as it reads it from the relay log and makes sure it is different from the slave's server_id. That is how MySQL Replication knows it is safe to execute that SQL statement. This rule is necessary in the event Circular (Master-Master,MultiMaster) Replication is implemented.

use select @@server_id; in sql command line to check config really on server.

2) Make sure the Slave's /etc/my.cnf has server_id actually set

Here is why: Same reason as in #1

3) Make sure the server_id in the Master's /etc/my.cnf is different from the server_id in the Slave's /etc/my.cnf

Here is why: Same reason as in #1

As a side note : If you setup multiple slaves, please make sure each slave has a different server_id from its master and its sibling slaves.

Here is why : Example

A master with 2 slaves
MASTER has server_id 1
SLAVE1 has server_id 2
SLAVE2 has server_id 2

Replication will become agressively sluggish on SLAVE2 because a sibling slave has the same server_id. In fact, it will steadily fall behind, catch a break, process a few SQL statements. This is the master's fault for having one or more slaves with identical server_ids. This is a gotcha that is not really documented anywhere. I've seen this dozens of times in my life time.

like image 42
RolandoMySQLDBA Avatar answered Oct 18 '22 02:10

RolandoMySQLDBA