四条命令搞定mysql主从
一 . 環(huán)境準(zhǔn)備
先上拓?fù)鋱D
兩個虛擬機(jī) 129和130.CentOS 6.3 安裝mysql 版本5.1 .yum 確保安裝配置一樣.
1 yum -y install mysql mysql-devel mysql-serverservice mysqld start
二 環(huán)境.
實驗環(huán)境 service iptables stop? || setenforce 0
三 主從配置
vi /etc/my.cnf
1 主服務(wù)器 2 log-bin 3 server-id=129 4 從服務(wù)器 5 log-bin 6 server-id=130主服務(wù)器上
1 grant replication slave on *.* to 'testsync'@'*' identified by '123456'創(chuàng)建賬號給從服務(wù)器用.
** use mysql; select * from user='testsync'? 能看到賬號建立.這一步一般不會有問題.
1 mysql> show master status\G 2 *************************** 1. row *************************** 3 File: mysqld-bin.000001 4 Position: 106 5 Binlog_Do_DB: 6 Binlog_Ignore_DB: 7 1 row in set (0.00 sec)記錄信息,從服務(wù)器會用到
?
從服務(wù)器上
1 change master to master_host = '192.168.137.129',master_user = 'testsync',master_password = '123456',2 master_log_file = 'mysqld-bin.000001',master_log_pos = 106;
啟動 slave start; 查看信息
1 mysql> show slave status\G 2 *************************** 1. row *************************** 3 Slave_IO_State: 4 Master_Host: 192.168.137.129 5 Master_User: testsync 6 Master_Port: 3306 7 Connect_Retry: 60 8 Master_Log_File: mysqld-bin.000001 9 Read_Master_Log_Pos: 106 10 Relay_Log_File: mysqld-relay-bin.000002 11 Relay_Log_Pos: 4 12 Relay_Master_Log_File: mysqld-bin.000001 13 Slave_IO_Running: Yes 14 Slave_SQL_Running: Yes 15 Replicate_Do_DB: 16 Replicate_Ignore_DB: 17 Replicate_Do_Table: 18 Replicate_Ignore_Table: 19 Replicate_Wild_Do_Table: 20 Replicate_Wild_Ignore_Table: 21 Last_Errno: 0 22 Last_Error: 23 Skip_Counter: 0 24 Exec_Master_Log_Pos: 106 25 Relay_Log_Space: 106 26 Until_Condition: None 27 Until_Log_File: 28 Until_Log_Pos: 0 29 Master_SSL_Allowed: No 30 Master_SSL_CA_File: 31 Master_SSL_CA_Path: 32 Master_SSL_Cert: 33 Master_SSL_Cipher: 34 Master_SSL_Key: 35 Seconds_Behind_Master: NULL 36 Master_SSL_Verify_Server_Cert: No 37 Last_IO_Errno: 1593 38 Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it). 39 Last_SQL_Errno: 0 40 Last_SQL_Error: 41 1 row in set (0.00 sec)
IO yes ,sql yes .其實主從配置還是很簡單的.
?
** server-id 必須有區(qū)別
??? server 之間網(wǎng)絡(luò)可達(dá),之間3306端口可達(dá)
log-bin 打開, log-position 一致. 主從服務(wù)器版本,初始數(shù)據(jù)信息一致.
?
done . that's all .
?
may tomorrow a clear morning.
本站博客皆為原創(chuàng),轉(zhuǎn)載請標(biāo)記下 小三爺.多謝~~!
?
轉(zhuǎn)載于:https://www.cnblogs.com/liuyuxing/p/5024802.html
總結(jié)
以上是生活随笔為你收集整理的四条命令搞定mysql主从的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 神经网络那些事儿(二)
- 下一篇: HTTP协议的特点