mysql5.7
在redhat6上安裝新版本的mysql,若存在舊版本的mysql應卸載掉
mysql —version 查看mysql版本
rpm -qa | grep mysql 查看已經安裝的mysql(需卸載的mysql包)
新版本安裝包:mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar
解壓並安裝:yum install -y mysql-community-*
安裝成功後啓動mysql服務:/etc/init.d/mysqld start
執行mysql_secure_installation進行安全初始化嚮導
[root@server1 mnt]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
這裏提示輸入root密碼,這裏與以往版本不同,新版本的密碼此時已經生成,在/var/log/mysqld.log中查詢temporary關鍵字:
2016-08-21T14:27:46.740332Z 1 [Note] A temporary password is generated for root@localhost: gw3;B:fDuJ?A
gw3;B:fDuJ?A即爲初始密碼,輸入密碼進行下一步
Remove anonymous users? (Press y|Y for Yes, any other key for No) :
####是否刪除匿名用戶,生產環境建議刪除
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
####是否禁止root遠程登錄,根據自己的需求選擇Y/n
Remove test database and access to it? (Press y|Y for Yes, any other key for No)
####是否刪除test數據庫
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
####是否重新加載權限表
提示All done!配置完成
AB複製
環境:server1.example.com 172.25.254.1
server2.example.com 172.25.254.2
將server1作爲主服務器,server2作爲從服務器,同步庫之前需對該庫進行數據手動同步
在server1上編輯mysql配置文件/etc/my.cnf添加以下參數:
log-bin=mysql-bin #啓動二進制日誌系統
binlog-do-db=test #二進制需要同步的數據庫名,如果需要同步多個庫,例如要再同步 westos庫,再添加一行“binlog-do-db=westos”,以此類推
server-id=1#必須爲 1 到 232–1 之間的一個正整數值
gtid-mode=ON #啓動GTID
enforce-gtid-consistency=on
官方文檔介紹:
該特性最大的用處就是,如果我們的備庫只是作爲只讀節點,那麼就可以關閉複製線程的binlog來降低複製的開銷(關閉 log_slave_updates),同時還會維持SQL線程擁有的事務GTID到系統表中。這樣即使主備切換,我們也不會丟失GTID。而在之前的版 本中,是不允許在打開GTID時關閉log_slave_updates的。
當然了,如果你的備庫是級聯的一部分,也就是說,是另外一臺備庫的主庫,這個特性就發揮不了作用啦。
在server2上編輯mysql配置文件/etc/my.cnf添加以下參數:
server-id=2
gtid-mode=on
enforce-gtid-consistency=on
在server1上
mysql> grant replication slave on *.* to 'yml'@'172.25.254.2' identified by 'Yml123456!@#';
# 授予用戶權限用於主從同步
mysql>change master to master_host='172.25.254.1',master_user='yml',master_password='Yml123456!@#',master_auto_position=1
#在server2上啓動從數據庫,添加主DB server指向 自動尋找position號
mysql> start slave;
mysql> show slave status\G;
測試:
在主服務端對test庫進行操作,並在從服務端查看是否同步,同時查看從服務端的mysql庫中的gitd表
mysql> select * from gtid_executed;
+--------------------------------------+----------------+--------------+
| source_uuid | interval_start | interval_end |
+--------------------------------------+----------------+--------------+
| 67066110-67ab-11e6-a71d-525400237b2e | 1 | 1 |
+--------------------------------------+----------------+--------------+
開啓並行複製
在從服務端配置文件中添加以下:
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16 ####開啓並行複製,線程爲16
master_info_repository=TABLE
relay_log_info_repository=TABLE ##這兩條爲官方推薦,能提升百分之50的性能
重啓服務
mysql> show processlist;
+----+-------------+-----------+-------+---------+-------+--------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+-------+---------+-------+--------------------------------------------------------+------------------+
| 23 | system user | | NULL | Connect | 25040 | Waiting for master to send event | NULL |
| 24 | system user | | NULL | Connect | 25039 | Slave has read all relay log; waiting for more updates | NULL |
| 25 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 26 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 27 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 28 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 29 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 30 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 31 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 32 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 33 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 34 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 35 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 36 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 37 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 38 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 39 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 40 | system user | | NULL | Connect | 25040 | Waiting for an event from Coordinator | NULL |
| 42 | root | localhost | mysql | Query | 0 | starting | show processlist |
+----+-------------+-----------+-------+---------+-------+--------------------------------------------------------+------------------+
此時多線程已經成功開啓