linux mysql5.6 主从配置,CentOS7+mysql5.6配置主从
一、安裝環境
操作系統:CentOS-7-x86_64-DVD-1611.iso
數據庫版本:mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
數據庫地址:
192.168.2.1(主)
192.168.2.2(從)
MySQL在5.6之前和之后的安裝方式是不一樣的。
首先保證3306端口的可用,或者關閉防火墻,兩臺機子可以互相ping
二、Master的配置
1.修改MySQL配置文件
[[email?protected] ~]# vim /etc/my.cnf
文件內容
[mysqld]
#開啟二進制日志
log-bin=mysql-bin
#標識唯一id(必須),一般使用ip最后位
server-id=2
#不同步的數據庫,可設置多個
binlog-ignore-db=information_schema
binlog-ignore-db=cluster
binlog-ignore-db=mysql
#指定需要同步的數據庫(和slave是相互匹配的),可以設置多個
binlog-do-db=test
2.重啟MySQL
service mysqld restart
3.進去mysql設置允許從庫獲得主庫日志 注:這里使用root用戶配置,不建議使用
[[email?protected] ~]# mysql -u root -p
#給從庫放權限
mysql>GRANT FILE ON *.* TO [email?protected] IDENTIFIED BY ‘root password‘;
mysql>GRANT REPLICATION SLAVE ON *.* TO [email?protected] IDENTIFIED BY ‘root password‘;
mysql>FLUSH PRIVILEGES;
4.重啟MySQL,登錄MySQL,查看主庫信息
mysql> show master status;
顯示內容
+------------------+----------+--------------+----------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+----------------------------------+-------------------+
| mysql-bin.000006 | 120 | ufind_db | information_schema,cluster,mysql | |
+------------------+----------+--------------+----------------------------------+-------------------+
1 row in set (0.00 sec)
mysql>
注:如果執行這個步驟始終為Empty set(0.00 sec),那說明前面的my.cnf沒配置對
三、Slave的配置
1.從庫配置
#開啟二進制日志(可以不配置)
log-bin=mysql-bin
server-id=3
binlog-ignore-db=information_schema
binlog-ignore-db=cluster
binlog-ignore-db=mysql
#與主庫配置一直
replicate-do-db=test
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60
4.重啟MySQL,登錄MySQL
#關閉Slave
mysql> stop slave;
#設置連接主庫信息
mysql> change master to master_host=‘192.168.2.1‘,master_user=‘root‘,master_password=‘root password‘,master_log_file=‘mysql-bin.000006‘, master_log_pos=120;
#開啟Slave
mysql> start slave;
注:上面的master_log_file是在配置Master的時候的File字段, master_log_pos是在配置Master的Position 字段。一定要一一對應
5.查看信息
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.1
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 120
Relay_Log_File: localhost-relay-bin.000006
Relay_Log_Pos: 520
Relay_Master_Log_File: mysql-bin.000006
Slave_IO_Running: Yes //顯示yes為成功
Slave_SQL_Running: Yes //顯示yes為成功,如果為no,一般為沒有啟動master
Replicate_Do_DB: test
Replicate_Ignore_DB: mysql
//上面的都是配置文件中的信息
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 357
Relay_Log_Space: 697
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error: //如果為no,此處會顯示錯誤信息
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: be0a41c0-2b40-11e8-b791-000c29267b6a
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
ERROR:
No query specified
注:如果Slave_IO_Running: No 出現下面的錯誤
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
說明主服務器的UUID和從服務器的UUID重復,更改方式
[[email?protected] ~]# vim /usr/local/mysql/data/auto.cnf #這是我的安裝路徑修改auto.cnf的server-uuid
以上主從MySQL已經可以使用了,歡迎各位多提bug
總結
以上是生活随笔為你收集整理的linux mysql5.6 主从配置,CentOS7+mysql5.6配置主从的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mybatis中(#{ })模糊查询li
- 下一篇: 渗透测试岗位面试题(重点:渗透测试思路)