设为首页 加入收藏

TOP

MySQL主从复制资料汇总(三)
2015-07-24 10:18:37 来源: 作者: 【 】 浏览:3
Tags:MySQL 主从 复制 资料 汇总
exists

drop table if exists innodb_index_stats;

drop table if exists innodb_table_stats;

drop table if exists slave_master_info;

drop table if exists slave_relay_log_info;

drop table if exists slave_worker_info;

执行完后,可以用show tables查看一下,看表的数据是否已经比删除之前减少了,如果减少了,说明你成功了!

[root@data02 test] cd/home/data/mysql/data/mysql

[root@data02 mysql]# ll *.ibd

-rw-rw----. 1 mysql mysql 98304 1? 9 02:08 innodb_index_stats.ibd

-rw-rw----. 1 mysql mysql 98304 1? 9 02:08 innodb_table_stats.ibd

-rw-rw----. 1 mysql mysql 98304 1? 9 02:08 slave_master_info.ibd

-rw-rw----. 1 mysql mysql 98304 1? 9 02:08 slave_relay_log_info.ibd

-rw-rw----. 1 mysql mysql 98304 1? 9 02:08 slave_worker_info.ibd

[root@data02 mysql]#

强行删除ibd文件:

[root@data02 mysql]# rm -f *.ibd

重启数据库,登录mysql

source/usr/test/mysql/share/mysql_system_tables.sql

show tables;

发现表已经回来了,表数据大概总数量为28个。

?

之后执行change master to,OK,搞定,如下所示:

mysql> stop slave;

Query OK, 0 rows affected, 1 warning (0.03sec)

?

mysql> CHANGE MASTER TOMASTER_HOST='192.168.52.129',MASTER_USER='repl',MASTER_PASSWORD='repl_1234',MASTER_LOG_FILE='mysql-bin.000141',MASTER_LOG_POS=120;

Query OK, 0 rows affected, 2 warnings (0.07sec)

mysql>

启动slave

mysql> start slave;

Query OK, 0 rows affected (0.02 sec)

?

mysql>

?

4.6 验证主从复制状态

在slave服务器上查看slave状态:

mysql> show slave status\G

*************************** 1. row***************************

Slave_IO_State: Waiting formaster to send event

Master_Host: 192.168.52.129

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000151

Read_Master_Log_Pos: 346

Relay_Log_File:mysql-relay-bin.000018

Relay_Log_Pos: 509

Relay_Master_Log_File: mysql-bin.000151

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:business_db,user_db,plocc_system

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: 346

Relay_Log_Space: 845

Until_Condition: None

这里主要看:

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Seconds_Behind_Master: 0

IO和SQL线程都是Yes以及Seconds_Behind_Master是0就表示从库正常运行了。

在master服务器上查看:

mysql> show full processlist;

+----+-----------------+----------------------+------+-------------+------+-----------------------------------------------------------------------+-----------------------+

| Id | User | Host | db | Command | Time | State |Info |

+----+-----------------+----------------------+------+-------------+------+-----------------------------------------------------------------------+-----------------------+

| 1| event_scheduler | localhost | NULL | Daemon | 5874 |Waiting on empty queue | NULL |

| 21 | root | localhost | NULL | Query | 0 | init | show full processlist |

| 24 | repl | 192.168.52.130:45665 | NULL |Binlog Dump | 88 | Master has sent allbinlog to slave; waiting for binlog to be updated | NULL |

+----+-----------------+----------------------+------+-------------+------+-----------------------------------------------------------------------+-----------------------+

3 rows in set (0.03 sec)

mysql>

看到有192.168.52.130:45665的线程在同步二进制数据

4.7 master添加数据验证

去master(192.168.52.129)上操作,添加表记录:

mysql> create table master_test select 1as a,'a' as b;

Query OK, 1 row affected (0.72 sec)

Records

首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MySQL事务学习 --> 分布式事务 下一篇mysql索引的设计和使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C/C++ 类模板与模板 (2025-12-27 01:49:52)
·C语言 模板化<templ (2025-12-27 01:49:49)
·C/C++模板类模板与函 (2025-12-27 01:49:46)
·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)