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 masterCopy codeThe Code is as follows: grant replication slave, replication client on *. * to 'slave '@ '192. 168.10.245' identified by '2016 ';
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;