安装2台mysql,参照搭建LAMP中的mysql部分mysql
配置mastersql
[root@localhost ~]# vi /etc/my.cnfide
log-bin=masterspa
server-id = 1rest
[root@localhost ~]# /etc/init.d/mysqld restartorm
[root@localhost ~]# /usr/local/mysql/bin/mysqlserver
# 受权备份权限给mysqlrepl用户,这里的192.168.10.39表示slave的IPblog
mysql> grant replication slave on *.* to 'mysqlrepl'@'192.168.10.39' identified by '123123';get
# 刷新同步
mysql> flush privileges;
# 锁定
mysql> flush tables with read lock;
# 查看结果中的File 和Position 列
mysql> show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| master.000001 | 391 | | |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)
配置slave
[root@localhost ~]# vi /etc/my.cnf
log-bin=slave
server-id = 2
[root@localhost ~]# /usr/local/mysql/bin/mysql
# 暂停slave
mysql> slave stop;
# 同步,这里必须跟master对应
mysql> change master to master_host='192.168.10.29',master_port=3306,master_user='mysqlrepl',master_password='123123',master_log_file='master.000001',master_log_pos=391;
# 启动slave
mysql> slave start;
# 查看主从配置成功与否
mysql> show slave status\G;
# 如下两项为Yes 表示成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes