Home  >  Article  >  Database  >  mysql数据库添加从库_MySQL

mysql数据库添加从库_MySQL

WBOY
WBOYOriginal
2016-06-01 13:39:161002browse

bitsCN.com
mysql数据库添加从库  mysql 主从配置在业务中应用不少,虽然了解其中机制,但从未进行处理过,为了深入了解下,对mysql进行了主从配置主库:3306从库:33071 主库配置:     My.conf代码  [mysqld]  #用自己数据库对应的即可  log-bin = /data0/mysql/3306/binlog/binlog  log-bin-index = /data0/mysql/3306/binlog/binlog.index    server-id = 1  #与从库配置与主库不能相同    注意:注意原配置文件中是否有binlog-do-db,如果指定了数据库,那只有这个数据库能够进行主从。根据需要判断是否需要配置(重启服务)  添加复制权限的用户(可读取2进制文件): GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '用户名'@'IP' IDENTIFIED BY '密码'; Java代码  mysql>  show master status;  查看file 和position       
mysql数据库添加从库_MySQL
 2 从库配置: My.conf代码  [mysqld]  #需要配置relaylog如果没有请创建对应权限的目录  relay-log-index = /data0/mysql/3307/relaylog/relaylog  #中继日志索引文件  relay-log-info-file = /data0/mysql/3307/relaylog/relaylog #中继日志文件    replicate-ignore-db=mysql                      #屏蔽对mysql的同步,可以设置多个用","分隔    server-id = 2 #与主库配置不同  同样需要注意binlog-do-db的配置        重启服务 数据库操作 Mysql代码  mysql>  >change master to master_host = '主库ip',  >master_port = 3306,  >master_user = '用户名',  >master_password = '密码',  >master_log_file = 'binlog.***',  >master_log_pos = 101;      master_log_file 和master_log_pos在主库中查询然后:Mysql代码  mysql> slave start;    # 查看从库状态    mysql> show slave status/G;  信息中:        Slave_IO_Running: Yes    Slave_SQL_Running: Yes说明配置成功,测试主库写入从库是否能够同步成功。  bitsCN.com

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