注意:若是主mysql已經跑了一段時間,須要用備份軟件把數據備份恢復到從服務器上去,確保主從服務器數據一致,不然可能報錯,並且mysql 只有5.6 之後才支持gtid,安裝時確保你的軟件支持gpid
1.安裝mysql
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm #下載mysql的yum源
yum install mysql57-community-release-el7-10.noarch.rpm -y # 安裝yum源
yum -y install mysql-community-server -y #yum 安裝mysql
2.編輯主配置文件mysql
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql user=mysql port=3306 server-id=1 gtid-mode=ON enforce-gtid-consistency=ON binlog_format=row log-bin=log-bin symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 我都是用的rpm默認路徑,實際安裝本身需求該路徑
3.編輯從文件sql
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock basedir=/usr/local/mysql user=mysql port=3306 server-id=2 gtid-mode=ON enforce-gtid-consistency=ON binlog_format=ROW log-bin=log-bin log_slave_updates=ON skip-slave-start=1 symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
4.建立具備複製權限的帳號,在主的上面建立grant replication slave on *.* to 'rep'@'192.168.%.%' identified by '123456';
5.從服務器配置鏈接
進入mysql配置change master to master_host='192.168.1.32', master_user='rep',master_password='123456',master_port=3306,master_auto_position=1;
6.啓動同步,查看
start slave;#啓動
show slave status;
這裏兩個yes 說明同步成功了服務器