I am trying to replicate my database using master slave replication on my wamp server. I have made the following changes to my my.ini file:
# Number of threads allowed inside the InnoDB kernel.The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8
#Defining the directory for logs and database and the server id
log-bin=C:\wamp\logs\mysql-bin.log
binlog-do-db=bank
server-id=2
On Master Server I configured this:
mysql> GRANT REPLICATION SLAVE
-> ON *.* TO 'root'#'slave_ip'
-> IDENTIFIED BY '';
On the slave server, I configured this:
mysql> CHANGE MASTER TO
-> MASTER_HOST='(master_ip)',
-> MASTER_PORT=3306,
-> MASTER_USER='root',
-> MASTER_PASSWORD='';
I got the error: Error 1198: This operation cannot be performed with a running slave; run stop slave first.
So I ran stop slave and nothing happened. Any help would be appreciated.
on master:
SHOW MASTER STATUS;
output is :
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 107 | karbord_test | |
+------------------+----------+--------------+------------------+
1 row in set
on slave:
STOP SLAVE;
CHANGE MASTER TO
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=107;
START SLAVE;
Related
Good Morning I have setup GTID replication between two mysql 8 databases they are for a Powerdns Setup When i make changes on the master I can only get one transaction to replicate then i am presented this error.
Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '0b5041c0-8e71-11ec-a064-00155d14ef09:5' at master log binlog.000001, end_log_pos 2500. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
If i run these commands
On master database:
mysql> reset master;
On slave database:
mysql> stop slave;
mysql> reset slave;
mysql> reset master;
mysql> start slave;
This clears the error and i am able to sync one more entry then i get presented with the above error again.
I used this guide to set it up
maybe i missed something in the setup.
https://medium.com/#michael_w_s/basic-setup-of-master-slave-gtid-replication-on-mysql-8-8f39ea29765c
any help would be greatly appreciated
Thank you all for taking time to reply
I have resolved this issue
My Main problem was i was importing all my data before setting up replication.
As soon as i setup replication first and then imported data all has been good.
I ran into the same issue, the error isn't actually shown there with that output, but rather will be in your error log, or one of the other locations it mentions in the message.
I found the root cause with:
tail /var/log/mysql/error.log
Your log location may be different. In my case it was a permissions related error, but it could be anything.
I have had the same issue and found that I was using an older style variable in the my.cnf master file:
binlog-do-db = mydatabase
In the error log on the replica, I was getting errors because of another database I hadnt specified: 'my_other_database not found'. This implied that it was ignoring the variable and replicating ALL databases.
On MySQL8, the correct variable name to use is:
binlog_do_db = mydatabase
This solved the issue for me. Just ensure that your master database is listed in the table under "Binlog_Do_DB":
mysql> SHOW MASTER STATUS;
+------------------+----------+----------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+----------------+------------------+-------------------+
| mysql-bin.000014 | 66373612 | mydatabase | | |
+------------------+----------+----------------+------------------+-------------------+
We operate a NDBCluster Version 8 and want to replicate a database in this cluster into a "standalone" InnoDB Database System. I followed this guide to implement the replication:
http://johanandersson.blogspot.com/2012/09/mysql-cluster-to-innodb-replication.html
but it seems, I have done something wrong and I don't know, how to debug it. I know the guide is very old, but I also read the chapter about the NDB Replication on MySQL https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-replication.html
Current behavior
The replication I set up by now replicates every statement like "Create Database" or "Create Table", even "INSERT" and "UPDATE" statements, as long as the NDBCLUSTER as Engine is not involved. I.e.: I can create a new Database in the cluster and it will be perfectly replicated to the slave. I can insert new datarows to a InnoDB table that I created on the cluster (I know, it is not actually saved in the cluster) and those data rows will be replicated to the slave. Inserting new data rows to a NDBCLUSTER table will result in no replication at all. If I execute the statement "SHOW MASTER STATUS" on the SQL Node in the Cluster before the insert to a NDBCLUSTER table and afterwords, I can see, that the Binlog Position has not changed at all.
Wanted behavior
I want the Replication to replicate data from tables with the NDBCLUSTER Engine to my Slave, that runs on InnoDB. I know there are limitations and we have to be carefull how to structure tables, that everything is compatible, etc.
Current Setup
We operate a MySQL NDB Cluster with 2 Management Nodes, 2 SQL Nodes and 4 Data Nodes and we want to replicate to one InnoDB Server
All Systems have Version 8 installed, run on Ubuntu 18.04 and all Systems have the Cluster Version of the MySQL Server installed. On of the SQL Nodes is chosen to do the replication. The config (/etc/my.cnf) of the Slave in the mysqld section is:
server-id=101
log-slave-updates=0
log-bin=binlog
binlog-format=MIXED
slave-exec-mode=IDEMPOTENT
expire-logs-days=5
The config of the Master (/etc/my.cnf) in the mysqld configuration (besides some cluster specific configuration) is:
binlog-format=ROW
log-bin=binlog
server_id=120
They are both at the same Position regarding the Binlog file.
mysql> SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000002 | 10547 | | | |
+---------------+----------+--------------+------------------+-------------------+
mysql> SHOW SLAVE STATUS \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.175.110
Master_User: replicationUser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000002
Read_Master_Log_Pos: 10547
Relay_Log_File: innodb-1-relay-bin.000005
Relay_Log_Pos: 365
Relay_Master_Log_File: binlog.000002
Slave_IO_Running: Yes
Slave_SQL_Running: No
[...]
Any Help in how to solve this Situation is appreciated!
Since MySQL Version 8.0.16 in addition to "log-bin" also a second variable has to be set in the my.cnf of the master & slave:
ndb-log-bin=ON
See https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-options-variables.html#sysvar_ndb_log_bin for more information.
I have two servers in different regions (eu, us) connected to the same mysql database, I've started with google cloud sql second generation but it's only available on us region.
The idea is to add a second sql nodes in the new region eu but I can't find any documentation about Master-Master replication so it is not supported at this time. Is this correct?
ps. both of my servers need read/write access.
With my operational google sql in us, can I just:
I create a new google sql cloud in eu.
Configure eu as an External Replicas for us.
Configure eu as External Masters for us.
I'm really confused! Any help will be appreciated.
/Ouss
Master-Master is not supported in Google Cloud SQL.
Solution from:
https://www.ryadel.com/en/mysql-master-master-replication-setup-in-5-easy-steps/
Successfully implemented on Linux Ubuntu 16.04 in google cloud platform
MySql 5.7 will not load on Debian.
/// Install MySQL on 2 VMs
A. On VMs sql1 & sql2
apt update
apt install mysql-server -y
P#ssW0rd2020 P#ssW0rd2020
B. Comment bind-address to allow global access
cd /etc/mysql/mysql.conf.d/
nano /etc/mysql/mysql.conf.d/mysqld.cnf
C. Restart MySQL Service (cnf changed)
systemctl restart mysql
systemctl status mysql
D. On sql1
nano /etc/mysql/conf.d/mysql.cnf
[mysqld] // note: not [mysql]
server-id=1
log-bin="mysql-bin"
binlog-ignore-db=test
binlog-ignore-db=information_schema
replicate-ignore-db=test
replicate-ignore-db=information_schema
relay-log="mysql-relay-log"
auto-increment-increment = 2
auto-increment-offset = 1
-------------------------------------
systemctl restart mysql
systemctl status mysql
D. On sql2
nano /etc/mysql/conf.d/mysql.cnf
[mysqld]
server-id=2
log-bin="mysql-bin"
binlog-ignore-db=test
binlog-ignore-db=information_schema
replicate-ignore-db=test
replicate-ignore-db=information_schema
relay-log="mysql-relay-log"
auto-increment-increment = 2
auto-increment-offset = 2
-------------------------------------
systemctl restart mysql (THIS WILL CREATE BIN LOG)
systemctl status mysql
again, flush privileges; ---supposed to
E. Create the Replicator User(s)
Configure on both sql1 & 2 (replicator password can be same for, or not)
mysql -u root -p
P#ssW0rd2020
CREATE USER 'replicator'#'%' IDENTIFIED BY 'P#ssW0rd2020';
GRANT REPLICATION SLAVE ON . TO 'replicator'#'%' IDENTIFIED BY 'P#ssW0rd2020';
flush privileges;
F. Start with fresh VMs with no databases (better) or mutual import/export databases into sql1 & 2
https://dev.mysql.com/doc/refman/8.0/en/copying-databases.html
G. Configure replication from sql1 to sql2
(make sql2 slave of sql1)
On sql1
SHOW MASTER STATUS;
example output:
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 448 | example | test, informatio |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
NOTE 'file' and 'position' values
On sql2
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST = '104.154.225.215', MASTER_USER = 'replicator', MASTER_PASSWORD = 'P#ssW0rd2020', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 448;
START SLAVE;
flush privileges;
H. Repeat for sql2 (make sql1 slave of sql2)
on sql2
SHOW MASTER STATUS;
example output:
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 448 | example | test, informatio |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
NOTE 'file' and 'position' values
On sql1
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST = '35.198.195.130', MASTER_USER = 'replicator', MASTER_PASSWORD = 'P#ssW0rd2020', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 448;
START SLAVE;
I. Test the Replication
Create a database on sql1 it will be replicated on sql2, vice versa.
Create a database on sql2 it will be replicated on sql1, vice versa.
SUCCESS IS SWEET! 🤓
I have one MySQL Master and several slave machines.
master-slave replication is set and works perfectly.
At this point, I want to add a new slave machine:
My question relates to the "CHANGE MASTER TO" command:
Assuming that all the files are available on the master, I will start from mysql-bin.000001, but from which position ? MASTER_LOG_POS=0 ? MASTER_LOG_POS=1 ? Something else ?
CHANGE MASTER TO
MASTER_HOST='...',
MASTER_USER='...',
MASTER_PASSWORD='...',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=WHAT_SHOULD_WRITE_HERE;
10x,
You should execute show master status; for example,
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000011 | 13966886 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
before taking dump on master and note the log position. Restore dump on slave and run change master to with same log position 13966886 which you have got before mysqldump.
If you have all the bin logs from the start of time you can use use master_log_file .000001 and pos=0. Most people don't have the binary logs from the master start anymore, so the position to use is the one that was when the dump was taken. The dump that you copied to your slave server. Or the position when you closed your master and copied data directories.
You already have a slave server so this makes it easier for you. You can stop the slave thread on the slave server, check the logfile name and position from the slave, copy the datafiles from the slave to the new server and start both.
The docs say to run SHOW MASTER STATUS: (http://dev.mysql.com/doc/refman/5.6/en/replication-howto-masterstatus.html)
SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 73 | test | manual,mysql |
+------------------+----------+--------------+------------------+
Your position is in the second column.
I have a web app with 2 web servers and 2 database servers. The dbs are setup for multi master replication. (this is the primary environment)
I also have the exact same setup on a different location acting as standby, in case the primary env fails. (this is the backup env)
What I need is for the backup env to be in sync with the dbs of the primary site. However, all dbs in both environments have already replication configured.
How can I achieve my goal?
Thanks
If this is standard MySQL rather than MySQL Cluster (and from your setup I think is has to be), you can't AFAIK.
If you have hierarchical replication then you could make it work, but with multimaster you can't. The basic problem is that a slave can only have one master which is set by the CHANGE MASTER TO command.
MySQL Cluster operates in a more complex manner, you have several servers in each cluster and then the cluster can be replicated to another cluster... or something.
Not very helpful I'm afraid.
You can sync the backup servers to one of the other masters, but the backup servers would not be masters to each other until you have a problem and then you change the master slave relationships yourself.
1 Configure The Master
First we have to edit /etc/mysql/my.cnf. or /etc/my.cnf We have to enable networking for MySQL, and MySQL should listen on all IP addresses, therefore we comment out these lines (if existant):
#skip-networking
skip-external-locking
bind-address=0.0.0.0
log-bin=mysql-bin.log
binlog-do-db=exampledb (database name)
server-id=1
Then we restart MySQL:
/etc/init.d/mysql restart
Create a user with replication privileges
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'#'%' IDENTIFIED BY '<some_password>'; (Replace <some_password> with a real password!)
FLUSH PRIVILEGES;
Take dump of database(exampledb) and run command
SHOW MASTER STATUS
It will give you result like
---------------+----------+--------------+------------------+
| File | Position | Binlog_do_db | Binlog_ignore_db |
+---------------+----------+--------------+------------------+
| mysql-bin.006 | 183 | database name| |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec
Write down this information, we will need it later on the slave!
Then leave the MySQL shell:
quit;
2 Configure The Slave
On the slave we first have to create the sample database exampledb:
mysql -u root -p
Enter password:
CREATE DATABASE exampledb;
quit;
store databse dump on slave
Now we have to tell MySQL on the slave that it is the slave, that the master is 192.168.0.100, and that the master database to watch is exampledb. Therefore we add the following lines to /etc/mysql/my.cnf or /etc/my.cnf if file doesnot exists copy from other location
server-id=2
master-host=192.168.0.100(ip address of master host machine)
master-user=slave_user(user name)
master-password=secret (password)
master-connect-retry=60
replicate-do-db=exampledb (database name)
Then we restart MySQL:
/etc/init.d/mysql restart
Finally, we must do this:
mysql -u root -p
Enter password:
SLAVE STOP;
In the next command (still on the MySQL shell) you have to replace the values appropriately:
CHANGE MASTER TO MASTER_HOST=’master ip address’, MASTER_USER='slave_user', MASTER_PASSWORD='<some_password>', MASTER_LOG_FILE='mysql-bin.006', MASTER_LOG_POS=183;
MASTER_HOST is the IP address or hostname of the master (in this example it is 192.168.0.100).
MASTER_USER is the user we granted replication privileges on the master.
MASTER_PASSWORD is the password of MASTER_USER on the master.
MASTER_LOG_FILE is the file MySQL gave back when you ran SHOW MASTER STATUS; on the master.
MASTER_LOG_POS is the position MySQL gave back when you ran SHOW MASTER STATUS; on the master.
Now all that is left to do is start the slave. Still on the MySQL shell we run
START SLAVE;
quit;
That's it! Now whenever exampledb is updated on the master, all changes will be replicated to exampledb on the slave. Test it!