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.
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 no idea of what I have done here, but my InnoDB engine seems to have gone from my MySQL server. I recently upgraded it from the dotdeb repository, then installed mysql-server.
There is no mention of InnoDB in my my.cnf except some comments which explain InnoDB is enabled by default, which I don't understand. There is also no mention of InnoDB in SHOW ENGINES.
Is there something I'm missing here?
If it matters, my MySQL server version is: 5.5.24-1~dotdeb.1 (Debian).
EDIT: SHOW ENGINES:
mysql> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MyISAM | DEFAULT | MyISAM storage engine | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.00 sec)
The problem is most probably a non-matching log file size: mysql expects the innodb log files to be exactly the size that is specified in the config file. To check whether this is really the issue, do the following:
sudo /etc/init.d/mysql restart
sudo tail -n 1000 /var/log/syslog
(I'm assuming you are on Debian)
If you see some errors reported there regarding innodb and log file size (Sorry, I can't remember the exact wording of the message), then the fix is easy:
locate the logfiles (probably /var/lib/mysql/ib_logfile0 and /var/lib/mysql/ib_logfile1)
stop the mysql server
rename the log files: sudo mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak etc.
start the mysql server
check in /var/log/syslog whether the errors are no longer happening
connect to mysql and check via SHOW ENGINES; whether InnoDB is available now...
Hope this helps!
The first thing to do is to run SHOW ENGINES at the MySQL prompt to confirm if Innodb is disabled.
If it is, check the error log for the MySQL server. It will have details on why InnoDB was disabled. There are several reasons MySQL might disable InnoDB on startup. For example, if the innodb log file size specified in my.cnf does not match the size of the existing log file(s) on disk.
I've got this problem with Debian 7 server with preinstalled mysql 5.5. There was no InnoDB engine after SHOW ENGINES
As severin mentioned before run this:
sudo /etc/init.d/mysql restart
sudo tail -n 1000 /var/log/syslog
I've got this one:
InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts.
And solution on other line:
InnoDB: You can disable Linux Native AIO by setting innodb_use_native_aio = 0 in my.cnf
After adding innodb_use_native_aio = 0 to my.cnf InnodDB appeared in SHOW ENGINES
Check if you have enough space on disk and where mysql.sock is stored.
Stop MYSQL
Edit my.cnf and increase:
innodb_buffer_pool_size=100M (May vary per case)
Add:
[mysqld]
innodb_force_recovery = 1
Execute the following
mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak
Start MySQL and take backups just in case.
Log in to mysql and: show engines; - Check to see that InnoDB is listed and SUPPORT = YES.
If all is good up until 6, exit and edit my.cnf setting this back:
[mysqld]
innodb_force_recovery = 0
Restart MySQL
Go to your websites, check that all works, and good luck!
PS - You may want to check what caused this, perhaps working on your production server, or restarting caused your log files to get corrupted. You're in the clear for now, so have a look around and make sure all else looks good, especially free disk space and offsite backups.
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;