来源:自学PHP网 时间:2015-04-16 10:50 作者: 阅读:次
[导读] 上次配置mysql的主从复制还是年初的时候,没想到现在又开始使用mysql了。话不多说,进入正题Master-Slave 搭建环境:Master:Os: rhel-server-6 3-x86_64Mysql: MySQL -5 5 35-1虚拟机:Virtual BOX...
上次配置mysql的主从复制还是年初的时候,没想到现在又开始使用mysql了。话不多说,进入正题 Master-Slave 搭建环境: Master: Os: rhel-server-6.3-x86_64 Mysql: MySQL -5.5.35-1 虚拟机:Virtual BOX Ip:192.168.56.12 Slave: Os: rhel-server-6.3-x86_64 Mysql: MySQL -5.5.35-1 虚拟机:Virtual BOX Ip:192.168.56.13 总体步骤: [mysqld] server-id=1 //必须是服务器唯一id,默认是0, log-bin=mysql-bin //必须启用二进制日志 replicate-do-db=zbdba 2、 在Master上创建一个有复制权限的用户 mysql>create user zbdba; mysql>grant replication slave on *.* to zbdba identified by '123456'; 3、 复制Master上的数据库到Slave mysql>flush tables with read lock; mysql> show master status -> ; +-----------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-----------------+----------+--------------+------------------+ | ogg1-bin.000003 | 107 | | | +-----------------+----------+--------------+------------------+1 row in set (0.00 sec) mysql>quit [root@ogg /]# /usr/bin/mysqldump zbdba -uroot -pmysql --opt | mysql zbdba -uroot -pmysql -h 192.168.56.13 需要在slave中授权: GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.56.13' IDENTIFIED BY 'mysql' WITH GRANT OPTION; mysql>unlock tables;4、 修改Slave配置文件(my.cnf) [mysqld] server-id=2 //必须是服务器唯一id,默认是0, log-bin=mysql-bin //必须启用二进制日志 replicate-do-db=zbdba 5、 Slave初始化复制 mysql>slave stop; mysql>CHANGE MASTER TO MASTER_HOST='192.168.56.12', MASTER_USER='zbdba',MASTER_PASSWORD='123456',MASTER_LOG_FILE='ogg1-bin.000003',MASTER_LOG_POS=107; mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.56.12 Master_User: zbdba Master_Port: 3306 Connect_Retry: 60 Master_Log_File: ogg1-bin.000003 Read_Master_Log_Pos: 107 Relay_Log_File: ogg2-relay-bin.000002 Relay_Log_Pos: 252 Relay_Master_Log_File: ogg1-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: zbdba 6、 测试 master: mysql> show tables; +-----------------+ | Tables_in_zbdba | +-----------------+ | guestbook | | test | | test1 | +-----------------+ create table test2 select * from test1; mysql> show tables; +-----------------+ | Tables_in_zbdba | +-----------------+ | guestbook | | test | | test1 | | test2 | +-----------------+salve: mysql> show tables; +-----------------+ | Tables_in_zbdba | +-----------------+ | guestbook | | test | | test1 | | test2 | +-----------------+ 4 rows in set (0.00 sec) 如果需要配置相互主从的关系,只需要在slave数据库上面建立对应用户,原master上面做一下初始化就行了。 7、 常见问题
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com