Modify Database Name of mysql replication

Source: Internet
Author: User

Modify Database Name of mysql replication

-- Replicate-rewrite-db = from_name-> to_name


Command-Line Format -- replicate-rewrite-db = old_name-> new_name
Option-File Format replicate-rewrite-db
Permitted Values
Type string


Tells the slave to translate the default database (that is, the one selected by USE) to to_name if it was from_name on the master. only statements involving tables are affected (not statements such as create database, drop database, and alter database), and only if from_name is the default database on the master. this does not work for cross-database updates. to specify multiple rewrites, use this option multiple times. the server uses the first one with a from_name value that matches. the database name translation is done before the -- replicate-* rules are tested.
If you use this option on the command line and the ">" character is special to your command interpreter, quote the option value. For example:
Shell> mysqld -- replicate-rewrite-db = "olddb-> newdb"
 
Applicability:
For example, the master and slave synchronize the test database, but because slave needs to change the name of test to testbak, The master cannot be changed, so this parameter is required.
Add in my. cnf
Binlog-do-db = test
Replicate-rewrite-db = test-> testbak
Restart mysql and modify the items in the test database of the master to check whether the hackers database of slave has been modified. Check whether the show slave status is normal.
 
To sum up, the slave modifies the database name, while the master remains unchanged.
 
 
Problem: When a slave query synchronization error occurs, you can use the following methods to solve the problem:
Slave stop;
Set global SQL _slave_skip_counter = 1;
Slave start;
However, data may be lost. First, let's take a look at the cause of the error.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.