安裝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