I want to achieve same server replication, such a way there will be two databases replicating one database on same server
Here is my configuration in my.ini
enter code here
server-id=1
log-bin
report-host=master-is-slave-host
log-bin=localhost-binlog
relay-log=localhost-relaylog
replicate-same-server-id=1
binlog-do-db=test
replicate-rewrite-db=test->myslave
**#replicate-rewrite-db=test->myslave2 does not work**
replicate-do-table=myslave.tblslave
**#replicate-do-table=myslave2.tblslave does not work**
the above code works fine for replication from db test to myslave on same server
I also want to achieve replication from db test to myslave2 on same server along with myslave
Basically it will be one master db and two slave db replicating the same master db
Regards,
Rizwan
Here is my code from my.cnf:
[mysqld]
server-id=1
report-host=master-is-slave-host
log-bin=/var/log/mysql/mysql-bin.log
log-bin-index=/var/log/mysql/mysql-bin.index
relay-log=/var/log/mysql/mysql-relay-bin.log
relay-log-index=/var/log/mysql/mysql-relay-bin.index
expire_logs_days=10
replicate-same-server-id=1
binlog-do-db=masterdb
log-error=/var/log/mysql/error.log
replicate-rewrite-db=masterdb->slavedb
replicate-do-table=slavedb.some_table
Related
I have a database myDB in the remote server (master) which has a table myTBL with some records. I want to sync the remote database with my localhost (slave) using MySQL Replication. So I have created the replication user in master and also a database with the name of myDB and the myTBL table in the localhost.
I want to use GTIDs method to syncing my databases because there is a description in MySQL website as follows:
MySQL 8.0 supports different methods of replication. The traditional
method is based on replicating events from the master's binary log,
and requires the log files and positions in them to be synchronized
between master and slave. The newer method based on global transaction
identifiers (GTIDs) is transactional and therefore does not require
working with log files or positions within these files, which greatly
simplifies many common replication tasks.
My master MySQL mysqld.cnf has:
server_id=1
enforce_gtid_consistency = on
gtid_mode = on
log_bin
log_slave_updates
and the status is:
File: ***-bin.000001
Position: 314969
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 9a670a45-be0a-11e9-be56-52540055d8e4:1-368
and my salve mysqld.cnf has:
server-id = 2
read_only = 1
gtid_mode=ON
enforce-gtid-consistency=ON
skip-slave-start=ON
and I use the following commands to start syncing in slave:
CHANGE MASTER TO MASTER_HOST='***', MASTER_USER='***', MASTER_PASSWORD='***', MASTER_AUTO_POSITION=1;
start slave;
And every thing is OK with this status in slave:
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
So, every new record that inserted to master database is synced with my slave (localhost) database. But the records which are inserted before syncing do not placed in localhost. How can I sync them? Or in the other words, How do I start syncing from the first records? (I saw in some websites which proposed using mysqldump to dump the first data, is there a better way?)
MySQL server + phpmyadmin
On the replication tab, it looks like someone already configured the master replication:
However, I do not see the following lines in my.cnf, which should have been added at the time the master was configured :
server-id=*****
log-bin=******
log-error=*****
How do I retrieve those values? Or how do I reset the master configuration so that I can perform the whole process myself (I also want to select/ignore new databases)?
I finally managed to solve my issue.
Note: The server-id is just a unique identifier that you can chose.
I had to enter those lines in the master's my.cnf file:
#master my.cnf
server-id = 1
log_bin = /var/lib/mysql/mysql-bin.log
binlog_do_db=database1
binlog_do_db=database2
binlog_do_db=database3
binlog_do_db=database4
binlog_do_db=database5
And those lines in the slave's my.cnf file:
#slave my.cnf
server-id = 2
replicate-do-db=database1
replicate-do-db=database2
replicate-do-db=database3
replicate-do-db=database4
replicate-do-db=database5
Then on the slave server's phpmyadmin go to replication tab and click Stop SQL Thread only and Stop IO Thread only
MySQL won't restart when I try "service mysqld restart"because I'm using this part in my.cnf
master-host = [private-IP-of-db01]
master-user = [replication-username]
master-password = [replication-password]
master-connect-retry = 60
when I comment out these parts! MySQL restarts fine. Why is that so? Also I have to include these lines in my.cnf because of master slave replication and I can't omit them out.
Usually master host information on the slave mysql server is stored in "master.info" file and maintained there. You may want to start mysql without adding the configuration to your "my.cnf" file, the only configuration you may want to add is a "server_id" , Once mysql is up and running, you should setup slave with 'change master command....'.
Please help!
I set up a master-slave replication based on the GTID mechanism.
The replication works OK, until a mysqld restart happens on slave. Then the mess begins...
After such a restart, I can not restore the replication.
When issuing a "START SLAVE" command I get the following an error message:
ERROR 1794 (HY000) at line 1: Slave is not configured or failed to
initialize properly. You must at least set --server-id to enable
either a master or a slave. Additional error messages can be found in
the MySQL error log.
Needless to say I did set server-id in my.cnf (see below).
In /var/log/mysqld.log file, I found the following error message:
[ERROR] Error creating master info: Multiple replication metadata
repository instances found with data in them. Unable to decide which
is the correct one to choose.
[ERROR] Failed to create or recover replication info repository.
I can not understand what have I done wrong.
The communication between master and slave is ssl-tunneled through stunnel, but I don't think this is a relevant fact, since until a restart everything works right.
The only way I found to re-establish the replication (after mysql restart) is to manually delete the mysql data files, and then load again the dump file imported from the master. (I use mysqldump). This is of course unreasonable.
Following are the my.cnf files:
On slave:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
server-id=2
log-bin=mysql-bin
binlog_format=ROW
relay_log=relay-log
skip-slave-start
enforce-gtid-consistency
gtid-mode=ON
log-slave-updates
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
On mater:
[mysqld]
server-id=1
log-bin=mysql-bin
binlog_format=ROW
gtid-mode=on
enforce-gtid-consistency
log-slave-updates
innodb_buffer_pool_size = 1G
query_cache_size = 32M
Slave machine: Centos 6.6, mysql 5.6.24.
Master machine: RHEL 6.6, mysql 5.6.10.
Any help wold be greatly appreciated!
Thanks
Nadav Blum
on master -
mysql> reset master;
[this command will clear binary logs of master and start with new. so save it if you want.]
when you start the slave mysqld, run the following command
mysql> stop salve;
mysql> reset slave;
mysql> change master to master_host='192.168.10.116', master_user='root', master_password='root', master_auto_position=1;
mysql> start slave;
mysql> show slave status \G
Now if all goes well then, you can restart the slave (if it is committed all the transaction then no problem else it will start to execute transection in your master binary log. You can check your relay log file)
Well, mystery solved.
Remember how I wrote that the issue has nothing to do with my usage of stunnel, as the mean for tunneling communication between master and slave ?
Well, I was wrong.
The thing is, I used localhost port 3307 as the end point for the slave communication to the master. (stunnel listened to this port and forwarded data to the master-server ip). So the "change master" was done via:
change master to master_host="localhost", master_port=3307, master_user="XXX", master_password="XXX", MASTER_AUTO_POSITION = 1;'
That "localhost" thing caused the mess. I changed it to "127.0.0.1", and now restarts cause no harm!
Thanks Hitech and Jaydee for your help!
Ran into the same problem yesterday.
Oracle support doc helped.
For people who don't have Oracle support.
CAUSE
The cause is that both TABLE and FILE replication repository metadata exist at the same time, but only one form should.
SOLUTION
Before setting up replication, remove the files specified by the my.cnf variables relay_log_info_file and master_info_file .
By default their names map to relay-log.info and master.info and they are located in the datadir. (I had to remove the master.info file)
And remove any residual configuration by executing:
STOP SLAVE;
SET SQL_LOG_BIN=0;
DELETE FROM mysql.slave_master_info ;
DELETE FROM mysql.slave_relay_log_info ;
SET SQL_LOG_BIN=1;
In-Short: My binary logs aren't starting even though log-bin is set and specified. I'm not sure how to fix it.
I have a MariaDB instance running as a service on windows that I am attempting to replicate to a MariaDB instance on a Ubuntu machine. I am using MySQL workbench 6.0 as much as I can to manage everything, and following the instructions from Oracle here for setting up master-slave replication: http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html
I have made it to the fourth chapter, where I allegedly have the master and slave both configured, and I am about to read-lock the master tables for an initial data dump to the slave before I start up replication. So I flushed the tables with read lock and checked the master status:
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
That last line didn't return any binary log information. Checking further, I ran:
SHOW BINARY LOGS;
and an error message confirmed that:
Error Code: 1381. You are not using binary logging
Master Config is like this:
[mysqld]
datadir = "C:/mysql/data"
port=3306
sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
default_storage_engine=innodb
innodb_buffer_pool_size=1535M
innodb_log_file_size=50M
feedback=ON
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
log-bin-index = "C:/mysql/logs/log-bin.index"
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
[client]
port=3306
How do I make sure the binary logs are rolling so I can continue with this?