Detailed description of synchronization configuration based on MySQL Master Slave

Source: Internet
Author: User

Environment:
PC: ubuntu 10.10 192.168.1.112 (master) 192.168.10.245 (slave)
MySQL: 5.1.49-1ubuntu8. 1-log
The database test already exists in the master.
First modify the mysql configuration file:/etc/mysql/my. cnf
[Master]
# Author: zhxia
Copy codeThe Code is as follows:
# Master synchronization settings
Server-id = 1
Log_bin =/var/log/mysql/mysql-test-bin.log
Expire_logs_days = 10
Max_binlog_size = 100 M
Binlog_format = mixed

[Slave]
# Author: zhxia
Copy codeThe Code is as follows:
Server-id = 2
Replicate-do-db = test
Replicate-do-db = blog
Log_bin =/var/log/mysql/mysql-bin.log
Relay_log =/var/log/mysql/mysql-relay-bin.log
Expire_logs_days = 10
Max_binlog_size = 100 M
# Binlog_do_db = test
# Binlog_ignore_db = include_database_name
Binlog_format = mixed
Slave-net-timeout = 6012 master-connect-retry = 10

Create a backup account on the master
Copy codeThe Code is as follows:
Grant replication slave, replication client on *. * to 'slave '@ '192. 168.10.245 'identified by '123 ';

Import the database in the master to slave,
First lock the table and prohibit write operations
Flush tables with read lock;
Export from the master: mysqldump-uroot-p test>/tmp/test. SQL
Import it to slave: mysql-uroot-p test </tmp/test. SQL. Remember to create a database named test first.
Go to mysql on the master and check the master status.

# Author: zhxia
Copy codeThe Code is as follows:
Mysql> show master status;
+ ----------------------- + ---------- + -------------- + ------------------ +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ----------------------- + ---------- + -------------- + ------------------ +
| Mysql-test-bin.000022 | 624 |
+ ----------------------- + ---------- + -------------- + ------------------ +
1 row in set (0.02 sec)

Go to Mysql on slave
# Author: zhxia
Copy codeThe Code is as follows:
Change master to master_host = '192. 168.1.112 ', master_user = 'slave', master_password = '000000', master_log_file = 'mysql-test-bin.000022 ', master_log_pos = 192;

Then start salve and check the status:
# Author: zhxia
Copy codeThe Code is as follows:
Start slave;

Mysql> show slave status \ G;
* *************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.112
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-test-bin.000022
Read_Master_Log_Pos: 624
Relay_Log_File: mysql-relay-bin.000005
Relay_Log_Pos: 533
Relay_Master_Log_File: mysql-test-bin.000022
Slave_IO_Running: Yes
Slave_ SQL _Running: Yes
Replicate_Do_DB: test, blog
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 624
Relay_Log_Space: 688
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

Finally, unlock the table on the master.
Unlock tables;

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.