标签:
本文主要记录mysql 主从配置。
经典的原理图
0、环境:
服务器A:
内网IP: 10.44.94.219
服务器B:
内网IP: 10.44.94.97
sudo apt-get update
sudo apt-get install mysql-server mysql-client
1 Master 配置:
GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO ‘backup‘@‘10.44.94.97‘ IDENTIFIED BY ‘fredric‘;
在my.cnf文件[mysqld]标签下增加
log-bin=mysql-bin.log
server-id=97
#server-id 建议采用ip地址末尾
备注:若binlog目录指定在其他地方,需要修改文件夹权限
配置完重启mysql 服务:sudo /etc/init.d/mysql restart
进入后输入:SHOW MASTER STATUS
显示:
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 107 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
2 Slave 配置
在my.cnf文件[mysqld] 标签下增加
log_bin = mysql-bin.log
server_id = 219
relay_log = mysql-relay-bin.log
log_slave_updates = 1 #Slave同步从Master同步数据过来的时候,log_slave_updates参数用来控制Slave是否把所有的操作写入到binary log
read_only = 1 #Slave为只读
CHANGE MASTER TO MASTER_HOST=‘10.44.94.219‘,
MASTER_USER=‘backup‘,
MASTER_PORT=3306,
MASTER_PASSWORD=‘fredric‘,
MASTER_LOG_FILE=‘mysql-bin.000002‘,
MASTER_LOG_POS=107;
START SLAVE;
输入:SHOW SLAVE STATUS\G; 显示:
Slave_IO_State: Waiting for master to send event Master_Host: 10.44.94.219 Master_User: backup Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 107 Relay_Log_File: mysql-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes
测试遇到的问题:
报错:Last_IO_Error: error connecting to master
SLAVE服务器无法通过局域网IP连接MASTER服务器的数据库,原因是mysql默认安装时只绑定127.0.0.1这个IP访问,因此要修改my.cnf注释掉其中的bind-address = 127.0.0.1
标签:
原文地址:http://www.cnblogs.com/Fredric-2013/p/5765683.html