Trying to set up replication master - slave.
Master my.cnf
[mysqld]
bind-address = 0.0.0.0
port = 3306
server-id = 1
log-bin = /var/lib/mysql/mysql-bin
replicate-do-db = Test
Slave my.cnf
[mysqld]
log_output = "FILE"
general_log_file = /var/log/mysql/mysql.log
general_log = 1
log_bin = /var/log/mysql/mysql-bin.log
server-id = 2
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
replicate-do-db = Test
SHOW SLAVE STATUS shows
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
In relay log i see query executed on master.
And Read_Master_Log_Pos also updates.
But in general_log_file appear only
130530 14:50:25 523 Query BEGIN
523 Query COMMIT /* implicit, from Xid_log_event */
And changes on master not executed on slave. What i have missed?
This could be due to the following option:
replicate-do-db = Test
The replicate-do-db option can be very tricky and can sometimes behave in a manner that appears illogical.
It will only replicate statements where the default ((that is, the one selected by USE) database is set. So in your example that would mean that this is replicated:
use Test;
insert into myTable (column) values (value);
But this will not be replicated:
insert into Test.myTable (column) values (value);
Try using the replicate-wild-do-table option instead:
replicate-wild-do-table=Test.%
Hopefully you will get some joy.
Related
The question is about MySQL-Master-Master replication. I have read a lot on the Internet, but there is a problem.
Source data:
A. MySQL 5.7.
Part of my. cnf about replication:
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay-log = /var/log/mysql/mysql-relay-bin
relay-log-index = /var/log/mysql/mysql-relay-bin.index
binlog_do_db = example
expire-logs-days = 7
auto_increment_increment = 2
auto_increment_offset = 1
log-slave-updates = 1
B. MySQL 5.7.
Part of my.cnf about replication:
server-id = 2
log_bin = /var/log/mysql/mysql-bin. log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay-log = /var/log/mysql/mysql-relay-bin
relay-log-index = /var/log/mysql/mysql-relay-bin.index
binlog_do_db = example
expire-logs-days = 7
auto_increment_increment = 2
auto_increment_offset = 2
log-slave-updates = 1
Server A is the active (primary) database server. Server B connects when server A is disabled / unavailable. In the beginning, the Master-Master replication was assembled (replication worked in both directions) and successfully worked for 2 days until I decided to test it. I started blocking access to server A to switch to server B and back. After several switches replication error 1062 appeared (Could not execute Write_rows event on table...).
And now question. What is incorrectly configured in my replication configuration? I understand that a lot depends on the product and the requests to it, but is there a universal Master-Master config?
Please consider below steps to test connection or failover:
let's assume, server A is active. So
enable read only first on server A.
then wait for couple of seconds and check show slave status twice
if positions are not changing. then move traffic on server B.
Follow same steps to reverse traffic on server A.
I would like to log my slow queries to a table, but keep my general log(?) logged in a table. I assume the general log is my binary log? MySQL docs are less than clear on this stuff. My MySQL server is setup as a replication master and these are the relevant logging stanzas from my.cnf.
# BINARY LOGGING #
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 3
max_binlog_size = 1000M
sync_binlog = 1
# LOGGING #
log_error = /var/log/mysql/mysql-error.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2
log_queries_not_using_indexes = 0
I'm afriad if I add something like this:
log_output = TABLE
general-log
expire_logs_days = 1
it will affect my binlog or start logging everything that's already written to my binlog to a table, which I don't want. I'm essentially just looking to have slow queries (a day or two's worth maybe) written to a table rather than a file, without affecting any of my other current logging.
I'm using Server version: 5.5.22-0ubuntu1-log (Ubuntu)
Thanks.
The setting log_output doesn't affect the binary log. It affects the general query log and the slow query log.
I have 2 slave mysql instances running on a host, which replicates data from a master on a different host. All instances are mysql 5.6. The relay bin log for the slave instances keep on changing even though there is no change from the master.
The following is the show slave status\G for slave1:
Slave_IO_State: Waiting for master to send event
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 210424
Relay_Log_File: mysqld1-relay-bin.000878
Relay_Log_Pos: 354
Relay_Master_Log_File: mysql-bin.000008
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
... : ...
A while later slave1's Relay_Log_File changed,
Slave_IO_State: Waiting for master to send event
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 210424
Relay_Log_File: mysqld1-relay-bin.001374
Relay_Log_Pos: 354
Relay_Master_Log_File: mysql-bin.000008
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
... : ...
but no change was made to the master, slave1 or slave2. Same thing is happening for slave2.
I suspect the two slaves are somehow sharing config/setup which they are not supposed to, but I was not able to determine what went wrong. The my.cnf file has
# The MySQL server mysqld1
[mysqld1]
user = mysql
port = 3301
pid-file = /usr/local/mysql1/data/mysqld1.pid
socket = /tmp/mysql1.sock
datadir = /usr/local/mysql1/data
log-bin=mysql-bin
binlog_format=mixed
gtid-mode=on
disable-gtid-unsafe-statements=true
log-slave-updates=true # needed to enable gtid
sync-master-info = 1
master-info-repository=TABLE
relay-log-info-repository=TABLE
server-id = 2
innodb_data_home_dir = /usr/local/mysql1/data
innodb_log_group_home_dir = /usr/local/mysql1/data
innodb_flush_log_at_trx_commit = 1
sync_binlog=1
[mysqld2]
user = mysql
port = 3302
pid-file = /usr/local/mysql2/data/mysqld2.pid
socket = /tmp/mysql2.sock
datadir = /usr/local/mysql2/data
log-bin=mysql-bin
binlog_format=mixed
gtid-mode=on
disable-gtid-unsafe-statements=true
log-slave-updates=true # needed to enable gtid
sync-master-info = 1
master-info-repository=TABLE
relay-log-info-repository=TABLE
server-id = 3
innodb_data_home_dir = /usr/local/mysql2/data
innodb_log_group_home_dir = /usr/local/mysql2/data
innodb_flush_log_at_trx_commit = 1
sync_binlog=1
Has anyone encountered something like this? Would running multiple instances this way require custom naming of relay logs?
Thanks.
It turned out the log-bin name needs to be different for the two slaves. I have changed them from
[mysqld1]
log-bin=mysql-bin
[mysqld2]
log-bin=mysql-bin
to
[mysqld1]
log-bin=slave1-bin
[mysqld2]
log-bin-slave2-bin
The sample configuration from Replication and auto-failover made easy with MySQL Utilities gave hints about this.
I am about to do a MySQL replication for my typo3 Database. There are two servers. You guessed it one is the Master and one is the Slave.
Master my.cnf:
[mysql]
server-id = 1
log-bin
expire_logs_days = 21
max_binlog_size = 500M
binlog-ignore-db=mysql
Slave my.cnf:
[mysql]
server-id = 2
binlog-ignore-db = mysql
replicate-ignore-db = mysql
auto-increment-offset = 1
expire_logs_days = 21
max_binlog_size = 500M
User on Master: repl#slaveip REPLICATION SLAVE, REPLICATION CLIENT
User on Slave: repl#masterip REPLICATION SLAVE, REPLICATION CLIENT
So far everything works, even if I change something on Master but if I delete the same thing on Master, Slave stops with this error message:
Last_SQL_Error: Error 'Duplicate entry '65021' for key 'PRIMARY'' on query. Default database: 'typo3'. Query: 'INSERT INTO sys_log (userid,type,action,error,details_nr,details,IP,tstamp,workspace) VALUES ('0','5','0','2','0','Core: Exception handler (WEB): Uncaught TYPO3 Exception: Reason: Segment "404" was not a keyword for a postVarSet as expected on page with id=0.<br />\n<br />\nAdditionally, http://www.21cdocs.de/404/ was not found while trying to retrieve the error document. | RuntimeException thrown in file /mnt/platte02/www/typo3/typo3_src-4.5.19/typo3/sysext/cms/tslib/class.tslib_fe.php in line 1542','masterip','1351240603','0')'
This is what show slave status\G shows me.
Any solutions how I force the Slave to override everything on it with Masters data?
- Timo
With slave-skip-errors = 1062 it skips the error but this isn't a good solution in my opinion
Update: obviously Typo3 is doing some mistakes on the sys_log table.
I need to log SQL to a file so i can check later which SQL run.
so i opened opt/lampp/etc/my.cnf and add these lines
log_slow_queries
log_queries_not_using_indexes =1
long_query_time = 1
slow_query_log = 1
slow_query_log_file = "/opt/lampp/logs/query.log"
but it did not logged the queries it even did not created the query.log file, so i created an empty file with the name, but still it's not working.
Edit
[mysqld]
log_slow_queries
log_queries_not_using_indexes =1
long_query_time = 1
slow_query_log = 1
general_log = 1
slow_query_log_file = /opt/lampp/logs/query.log
general_log_file = "/opt/lampp/logs/query.log"
This will only log slow queries. You need the general log if you want to see all queries.
general_log = 1
general_log_file = "/opt/lampp/logs/query.log"
Note that you'll need to restart the server for this to take effect. Also, you should only use this type of logging during testing as it does cause slowdown.
As other users mentioned, this could be a permissions issue. First, check what user MySQL is running as via ps -u -p $(pgrep mysql). The username will be displayed on the first column under USER. In your case, it seems the user is nobody. You can view the default group of a user via groups nobody. This should print something like nobody : nogroup.
To fix the permissions on the file, just run chown nobody:nogroup /opt/lampp/logs/query.log.
Be sure to give the correct permission :
chown mysql:mysql filename
also when i last did it , i had to restart the mysql service :
service mysqld restart
log_slow_queries
is deprecated
It now has to look like that:
slow_query_log
log_queries_not_using_indexes =1
long_query_time = 1
slow_query_log = 1
general_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
general_log_file = /var/log/mysql/mysql-slow.log
The process probably doesn't have permission to write to that directory. Make sure MySQL has permission to write there, or try logging somewhere less restricted.
This will only log slow queries. You need the general log if you want to see all queries.
general_log = 1
general_log_file = "/opt/lampp/logs/query.log"
Note that you'll need to restart the server for this to take effect. Also, you should only use this type of logging during testing as it does cause slowdown.
Also Note that mysql needs permissions over folder too, in my case, I changed:
general_log_file = "/opt/lampp/logs/query.log"
for
general_log_file = "/var/log/mysql/query.log"
But I have mysql installed from software center, without lampp, when I execute ls -l over /var/log/, it shows
drwx------ 8 mysql mysql 4096 sep 25 23:22 mysql
PD:I change the my.cn file and restart mysql, without create the query.log file in the specified path, mysql automatically create it