7. 在备份文件weibo.sql查看binlog和pos值
#head-25weibo.sql
--CHANGEMASTERTOMASTER_LOG_FILE="mysql-bin.000001",MASTER_LOG_POS=107;#大概22行
8. 从库设置从这个日志点同步,并启动
mysql>changemastertomaster_host="192.168.18.212",
->master_user="sync",
->master_password="sync",
->master_log_file="mysql-bin.000001",
->master_log_pos=107;
mysql>startslave;
mysql>showslavestatusG;
ERROR2006(HY000):MySQLserverhasgoneaway
Noconnection.Tryingtoreconnect...
Connectionid:90
Currentdatabase:***NONE***
***************************1.row***************************
Slave_IO_State:Waitingformastertosendevent
Master_Host:192.168.18.212
Master_User:sync
Master_Port:3306
Connect_Retry:60
Master_Log_File:mysql-bin.000001
Read_Master_Log_Pos:358
Relay_Log_File:mysqld-relay-bin.000003
Relay_Log_Pos:504
Relay_Master_Log_File:mysql-bin.000001
Slave_IO_Running:Yes
Slave_SQL_Running:Yes
......
可以看到IO和SQL线程均为YES,说明主从配置成功。
9. 从库查看weibo库里面的表
mysql>showtables;
+---------------------------+
|Tables_in_weibo|
+---------------------------+
|test_tb|
发现刚才模拟创建的test_tb表已经同步过来!
二、xtrabackup方式(推荐)
在上面配置基础上做实验,先删除掉从库配置:
mysql>stopslave;#停止同步
mysql>resetslave;#清除从连接信息
mysql>showslavestatusG;#再查看从状态,可以看到IO和SQL线程都为NO
mysql>dropdatabaseweibo;#删除weibo库
此时,从库现在和新装的一样,继续前进!
1. 主库使用xtrabackup备份
#innobackupex--user=root--password=123./
生成一个以时间为命名的备份目录:2015-07-01_16-49-43
#ll2015-07-01_16-49-43/
total18480
drwxr-xr-x5rootroot4096Jul116:49./
drwx------4rootroot4096Jul116:49../
-rw-r--r--1rootroot188Jul116:49backup-my.cnf
-rw-r-----1rootroot18874368Jul116:49ibdata1
drwxr-xr-x2rootroot4096Jul116:49mysql/
drwxr-xr-x2rootroot4096Jul116:49performance_schema/
drwxr-xr-x2rootroot12288Jul116:49weibo/
-rw-r--r--1rootroot21Jul116:49xtrabackup_binlog_info
-rw-r-----1rootroot89Jul116:49xtrabackup_checkpoints
-rw-r--r--1rootroot563Jul116:49xtrabackup_info
-rw-r-----1rootroot2560Jul116:49xtrabackup_logfile
2. 把备份目录拷贝到从库上
#scp-r2015-07-01_16-49-43root@192.168.18.214:/home/root
3. 从库上把MySQL服务停掉,删除datadir目录,将备份目录重命名为datadir目录
#sudorm-rf/var/lib/mysql/
#sudomv2015-07-01_16-49-43//var/lib/mysql
#sudochownmysql.mysql-R/var/lib/mysql
#sudo/etc/init.d/mysqlstart
#ps-ef|grepmysql#查看已经正常启动
mysql88321016:55?00:00:00/usr/sbin/mysqld
4.在主库创建test_tb2表,模拟数据库新增数据
mysql>createtabletest_tb2(idint,namevarchar(30));
5. 从备份目录中xtrabackup_info文件获取到binlog和pos位置
#cat/var/lib/mysql/xtrabackup_info
uuid=201af9db-1fce-11e5-96b0-525400e4239d
name=
tool_name=innobackupex
tool_command=--user=root--password=..../
tool_version=1.5.1-xtrabackup
ibbackup_version=xtrabackupversion2.2.11basedonMySQLserver5.6.24Linux(x86_64)(revisionid:)
server_version=5.5.43-0ubuntu0.12.04.1-log
start_time=2015-07-0116:49:43
end_time=2015-07-0116:49:46
lock_time=1
binlog_pos=filename"mysql-bin.000001",position429#这个位置
innodb_from_lsn=0
innodb_to_lsn=1598188
partial=N
incremental=N
format=file
compact=N
compressed=N
6. 从库设置从这个日志点同步,并启动
mysql>changemastertomaster_host="192.168.18.212",
->master_user="sync",
->master_password="sync",
->master_log_file="mysql-bin.000001",
->master_log_pos=429;
mysql>startslave;
mysql>showslavestatusG;
***************************1.row***************************
Slave_IO_State:Waitingformastertosendevent
Master_Host:192.168.18.212
Master_User:sync
Master_Port:3306
Connect_Retry:60
Master_Log_File:mysql-bin.000001
Read_Master_Log_Pos:539
Relay_Log_File:mysqld-relay-bin.000002
Relay_Log_Pos:363
Relay_Master_Log_File:mysql-bin.000001
Slave_IO_Running:Yes
Slave_SQL_Running:Yes
......
可以看到IO和SQL线程均为YES,说明主从配置成功。
9. 从库查看weibo库里面的表
mysql>showtables;
+---------------------------+
|Tables_in_weibo|
+---------------------------+
|test_tb|
|test_tb2|
发现刚才模拟创建的test_tb2表已经同步过来。
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快