Home > Database > Mysql Tutorial > body text

MYSQL主主切换(主库未宕机)_MySQL

WBOY
Release: 2016-06-01 13:29:03
Original
1258 people have browsed it

bitsCN.com

MYSQL主主切换(主库未宕机)

 

将主主(3307写--3308读)切换 

前提:停止业务,3307上不再有任何写操作 

一、将3307设为只读。命令行操作 

# 修改配置文件 

vim /home/bbq/mysql/mysql-3307/cnf/my.cnf 

# 在[mysqld]中增加 

read_only 

 

# 重新启动mysqld3307 

service mysqld3307 restart 

 

二、检查主库的sql是否在从库上都执行完。mysql客户端操作 

# 方法一 

# 3308(读转写)执行 

SHOW PROCESSLIST; 

其中一个user='system user'的线程 

如果State值为"Reading event from the relay log",代表正在执行主库同步的中继日志sql 

如果State值为"Slave has read all relay log; waiting for the slave I/O thread to update it",代表已经执行完主库同步的中继日志sql 

 

# 方法二(简单不易出错,推荐) 

#3307执行: 

show master status # 记录File、Position 

#3308执行: 

select master_pos_wait(File, Position); 

 

 

三、将3308设为可写。命令行操作 

# 修改配置文件 

vim /home/bbq/mysql/mysql-3308/cnf/my.cnf 

# 在[mysqld]中删除 

# read_only 

 

# 重新启动mysqld3308 

service mysqld3308 restart 

 

 

 

bitsCN.com
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!