阿里云服务快到期了,重新换了腾讯云的服务器。数据库懒的备份,直接配置一个主从同步,到时候就不用在去备份恢复。
Master Server配置
添加同步账户
连接Mysql服务[mysql -uroot -pxxxx]
mysql> create user repl;
Query OK, 1 rows affected (0.01 sec)
mysql> GRANT REPLICATION SLAVE ON . TO ‘repl‘@’192.168.0.%’ IDENTIFIED BY ‘mysql’; #指定那个段的IP才能连接服务
Query OK, 1 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 1 rows affected (0.01 sec)
修改/etc/my.cnf文件
[mysqld]
port=13577
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
server-id=1 # server id
log-bin=master-bin # master-bin日志文件
log-bin-index=master-bin.index
binlog-do-db=itools # 指定同步那个库
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
重启Master Server的Mysql服务
systemctl restart mysql.service
查看Master的状态
连接Mysql服务[mysql -uroot -pxxxx]
执行show master status;
mysql> show master status; |
Slave Server配置
修改/etc/my.cnf文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
[mysql.server]
user=mysql
[client]
socket=/var/lib/mysql/mysql.sock
重启Master Server的Mysql服务
systemctl restart mysql.service
添加Master配置
连接Mysql服务[mysql -uroot -pxxxx]
mysql> change master to master_host='xxx.xxx.xxx.xxx', # Master的IP |
查看Slave的状态
mysql> show slave status; |
主要看Slave_IO_Running
和Slave_SQL_Running
是否都是YES
。
验证
在Master Server的同步里面插入表或者数据, Slave会自动进行同步。