0
votes

I am creating the MySQL master-slave replication on CentOS 7 below are the configuration files details of both the server:

Master server's my.cnf

[mysqld]
server-id=1
log-bin=mysql-bin

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Slave Server's my.cnf

[mysqld]
server-id=2
replicate-wild-do-table=db1%.%

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock


symbolic-links=0

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Database details given below:

Master Server

create database db1;
create table db1.dbtb1(name varchar(100));

Slave Server

create database db1slave;
create table db1slave.dbtb1(name varchar(100));

AS you can see the Database name on both the sever are different for that I have use the below statement into the slave server for replication.

replicate-wild-do-table=db1%.%

But when I try to insert data into the Master Data base server I got the below error or slave server status:

Error 'Table 'db1.dbtb1' doesn't exist' on query. Default database: ''. Query: 'insert into db1.dbtb1 values ('Punu')'

Slave server Status:

Slave_IO_State: Waiting for master to send event
Master_Host: IP address
              Master_User: repl
              Master_Port: 3306
            Connect_Retry: 60
          Master_Log_File: mysql-bin.000003
      Read_Master_Log_Pos: 971
           Relay_Log_File: mysqld-relay-bin.000002
            Relay_Log_Pos: 283
    Relay_Master_Log_File: mysql-bin.000003
         Slave_IO_Running: Yes
        Slave_SQL_Running: No
          Replicate_Do_DB:
      Replicate_Ignore_DB:
       Replicate_Do_Table:
   Replicate_Ignore_Table:
  Replicate_Wild_Do_Table: db1%.%
Replicate_Wild_Ignore_Table:
               Last_Errno: 1146
               Last_Error: Error 'Table 'db1.dbtb1' doesn't exist' on query. Default database: ''. Query: 'insert into db1.dbtb1 values ('Punu')'
             Skip_Counter: 0
      Exec_Master_Log_Pos: 760
          Relay_Log_Space: 668
          Until_Condition: None
           Until_Log_File:
            Until_Log_Pos: 0
       Master_SSL_Allowed: No
       Master_SSL_CA_File:
       Master_SSL_CA_Path:
          Master_SSL_Cert:
        Master_SSL_Cipher:
           Master_SSL_Key:
    Seconds_Behind_Master: NULL
    Master_SSL_Verify_Server_Cert: No
            Last_IO_Errno: 0
            Last_IO_Error:
           Last_SQL_Errno: 1146
           Last_SQL_Error: Error 'Table 'db1.dbtb1' doesn't exist' on   query. Default database: ''. Query: 'insert into db1.dbtb1 values ('Punu')'
 Replicate_Ignore_Server_Ids:
         Master_Server_Id: 1
              Master_UUID: 2fc2ef76-c87a-11e6-ae22-000d3aa2da57
         Master_Info_File: /var/lib/mysql/master.info
                SQL_Delay: 0
      SQL_Remaining_Delay: NULL
  Slave_SQL_Running_State:
       Master_Retry_Count: 86400
              Master_Bind:
  Last_IO_Error_Timestamp:
 Last_SQL_Error_Timestamp: 161227 18:40:36
           Master_SSL_Crl:
       Master_SSL_Crlpath:
       Retrieved_Gtid_Set:
        Executed_Gtid_Set:
            Auto_Position: 0

If I will take the same database name it will work fine. But as per my requirement I can't put the database name same on both the server.

Simply I want that when the table "dbtb1" updated in Master server database then it will be replicated to the slave database table.

I have also try the below options in the slave my.cnf file:

1

   replicate-wild-do-table=db1%.dbtb1

2

   replicate-rewrite-db="db1->db1slave"

Above option will work fine if I insert record but it will not reflect when I delete or update record.

3

 replicate-wild-do-table=%.dbtb1
1

1 Answers

0
votes

your option replicate-wild-do-table=db1%.% will replicate all table in all schemas starts with db1% ans also replicate all tables start with %. so it will replicate all tables. thats a wrong config.

use the replicate-rewrite-db option to config this. read this below.

https://mariadb.com/resources/blog/multisource-replication-how-resolve-schema-name-conflicts