I’ve been experimenting with master-master replication between two MySQL servers but with different database names and I’ve come accross a bit of a stumbling block. It appears that although UPDATEs work correctly as expected, INSERTs do not.
While I would say that this is a bug or at least a problem with my setup, it appears that MySQL says that this is a feature (here and here).
If then, as MySQL say, it only works on the default database, then how can this setting have a practical real world purpose?
Am I missing something ?
For reference the relevant parts in my.cnf. I’ve been testing this by doing inserts and updates from within phpMyAdmin if that makes any difference.
master
log-bin=mysql-bin
binlog_do_db=db1
slave
replicate-rewrite-db=db1->db2
replicate-wild-do-table=db2.table1
Replication-rewrite-dbusage is same as other replication options. Not onlyReplication-rewrite-dbworks on the default database, but these also:replicate-do-db, replicate-ignore-db, binlog-do-db and binlog-ignore-db. Refer this and this.There are real world purpose, else MySQL wouldn’t have implemented this option. And it works only on default database because–
You should also know the replication rules. From here.
I tested phpmyadmin by issuing
INSERT, DELETE and UPDATEand noticed(By enablinggeneral_query_log) that it issuesINIT DB 'db_name'(‘Init DB’ is logged for themysql_select_db()API call).For example:
So ultimately the replication shouldn’t break as phpmyadmin does it correctly by executing USE db before every query.