4、让从服务器同步主服务器当前时间之前所有数据。
4.1首先完全备份主服务器,复制到从服务器上。
# MySQLdump --master-data=2 --all-databases --lock-all-tables --events > /root/all.sql
# scp all.sql b:/root/
4.2修改配置文件/etc/my.cnf将之前的配置先注释掉,初始化完了再启用。
4.3让从服务器重新初始化,在/usr/local/mysql目录下执行命令
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
4.4启用配置文件中的配置
Server -id = 20
Read-only=1
Relay-log = /mydata/data/relay-bin
skip-slave-start=1
# log-bin = /mysql-bin 关闭二进制日志
4.5 启动服务,导入
# service mysqld start
# mysql < all.sql
4.6 查看是否导入成功
# mysql
Mysql> show databases;
4.6 启动从服务器,指定复制的起始位置
主服务器中
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 437 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
从服务器中
mysql> change master to master_host='172.16.5.11', master_user='user',
master_password='pass',master_log_file='mysql-bin.000004',master_log_pos=437;
启动从服务器并查看从服务器状态
Mysql> start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.5.11
Master_User: user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 437
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 421
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 437
Relay_Log_Space: 571
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
下面可以进行测试,是否可以同步主服务器的数据,应该没什么问题,不再演示。
