[英]Replicate tables from different database of same mysql server
I have one server with 2 databases, and i want to replicate several tables from one database to another. 我有一台服务器有2个数据库,我想将多个表从一个数据库复制到另一个数据库。 Purpose is that we uses same user's table that used in projects.
目的是我们使用与项目中使用的相同的用户表。
As in anothers tables used InnoDB with foreign keys to users table i've chosen a replication way. 就像在其他表中使用InnoDB和用户表的外键一样,我选择了一种复制方式。
For that I made the changes for my.cnf 为此,我对my.cnf进行了更改
master-user=root
server-id = 2
replicate-rewrite-db = dou->jobs
replicate-do-table = jobs.auth\_user
replicate-wild-do-table = jobs.geo\_%
replicate-do-table = jobs.user\_profile
replicate-same-server-id = 1
report-host = master-is-slave
binlog-do-db = dou
log-bin
after syncing tables from binlog-do-db
and starting slave error.log next lines appears: 从
binlog-do-db
同步表并启动slave error.log后,出现以下几行:
111112 15:10:22 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='localhost', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='localhost', master_port='3306', master_log_file='mysql-bin.000074', master_log_pos='106'.
111112 15:10:36 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000074' at position 106, relay log '/var/log/mysql/dell-relay-bin.000001' position: 4
111112 15:10:36 [Note] Slave I/O thread: connected to master 'root@localhost:3306',replication started in log 'mysql-bin.000074' at position 106
Seems that on this step everything is ok, and show slave status
shows no errors. 似乎在此步骤中一切正常,并且
show slave status
显示任何错误。
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000074
Read_Master_Log_Pos: 814
Relay_Log_File: dell-relay-bin.000002
Relay_Log_Pos: 959
Relay_Master_Log_File: mysql-bin.000074
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table: jobs.user\_profile,jobs.auth\_user
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: jobs.geo\_%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 814
Relay_Log_Space: 1113
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
ERROR:
No query specified
The thing is that master changes does not affect slave but slave status changes. 问题是主机更改不会影响从机,但会影响从机状态。
Thanks for any help in solve that problem. 感谢您为解决该问题提供的帮助。
Out of interest would a view do what you want? 出于兴趣,视图会做什么?
I really don't think running replication on the same instance of mysql into to the same instance is a good idea. 我真的不认为将mysql的相同实例上的复制运行到相同的实例中不是一个好主意。
The other option you might want to investigate if server hardware is a problem, would to run multiple instances of mysql running off different ports on the same machine, which might help you achieve what you are looking for. 您可能想调查服务器硬件是否有问题的另一种方法是,在同一台计算机上的多个端口上运行mysql的多个实例,这可能有助于您实现所需的功能。 This is something i am using in a test environment for simulated master DB failure and slave DB promotion.
这是我在测试环境中用于模拟主数据库故障和从数据库升级的内容。
I won't tell you that replicating table to the same DB is bad idea, cause of several times increased IO. 我不会告诉您将表复制到相同的DB是个坏主意,因为IO会增加几倍。
Slave is not updated, because server-id is the same for both master and slave. 从站不会更新,因为主服务器和从服务器的server-id相同。 Usually slave ignores updates with the same server-id as it's own.
通常,slave会忽略具有相同服务器ID的更新。
Add replicate-same-server-id to my.cnf. 将复制相同服务器ID添加到my.cnf。 replicate-same-server-id documentation
复制相同服务器ID文档
There is many situations on where you can achive more optimisations for example. 例如,在许多情况下,您可以实现更多优化。 DB1 replicates to DB2 (same server).
DB1复制到DB2(同一服务器)。 From where DB2 only has data stored for as long as 1 week.
从那里DB2仅存储了长达1周的数据。 all data that is older than 1 weeks gets deleted (On db2).
删除所有早于1周的数据(在db2上)。 in such a setup for example a high traffic db server where u need it to be as clean as possible a dual db setup on the same server uses "less" resources from the server if what your server do most of the time is read data from the database.
在这样的设置中,例如高流量的db服务器,如果您服务器大部分时间从服务器读取数据,则您需要尽可能干净的同一台服务器上的双数据库设置使用服务器中的“较少”资源数据库。 I have such a setup buth i use 4 diferent servers.
我有这样的设置,但是我使用了4个不同的服务器。 server 1) 3 days.
服务器1)3天。 server 2) 30 days.
服务器2)30天。 server 3) 2 months, and server 4 all data from start.
服务器3)2个月,服务器4从头开始所有数据。 (Server 4 mostly used for gething very old registers not so much used. Sorry for my english buth i think i made a point on where you CAN and should use db replication on the same server to reduce memmory usage and cpu usage.
(服务器4主要用于获取非常旧的寄存器,但使用的很少。对不起,我的英语霸王,我想我对您可以在哪里提出了意见,应该在同一服务器上使用db复制来减少内存使用和cpu的使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.