mysql主从复制运维_Mysql主从复制配置
環(huán)境:master:?192.168.240.131
Slave:?192.168.240.130
需要復制的數(shù)據(jù)庫:test
1.???????Master服務器啟動mysql,
a)?????????#mysql?–uroot?–proot
b)????????創(chuàng)建一個有復制權限的用戶,只限slave遠程連接訪問.
i.??????????????mysql>grant?replication?slave?on?*.*?to?navy@192.168.240.130 identified?by?‘password’;
ii.??????????????mysql>flush?privileges;
c)?????????mysql>flush?tables?with?read?lock;?#鎖定master服務器所有表的寫入。
d)????????重新打開一終端,備份要復制的數(shù)據(jù)庫。
i.??????????????#tar?-zcvf?test.tar.gz?/data/mysql_db/test/????//test所在路徑/data/mysql_db/test/即一個庫。
ii.???????將test.tar.gz復制到從服務器上并減壓到相應的目錄下
e)?????????返回上一終端。
i.??????????????Mysql>show?master?status;
+------------------+----------+--------------+------------------+
|?File?????????????|?Position?|?Binlog_Do_DB?|?Binlog_Ignore_DB?|
+------------------+----------+--------------+------------------+
|mysql-bin.000013|???????106?|?test?????????|??????????????????|
+------------------+----------+--------------+------------------+
1?row?in?set?(0.01?sec)
其中mysql-bin.000013和106二個值將是slave與master的同步點。
f)??????????給數(shù)據(jù)庫解鎖(當備份完成后) mysql>unlock?tables;
g)?????????編輯mysql的配置文件。Vim?/etc/my.cnf設置這三個參數(shù),沒有的添加,有的直接更改即可。
log-bin=mysql-bin
server-id??=?1
binlog-do-db=test
保存退出。
2.???????Slave服務器配置
a)?????????將從master中備份的庫解壓到相應路徑下(退庫的導入)
i.??????????????#tar?zxvf?test.tar.gz
b)????????修改my.cnf
server-id=2
master-host=192.168.240.131
master-user=?navy
master-password=?password
log-bin=
3.???????重啟master,?slave的mysql服務
a)?????????注意順序,先重啟master-à然后是slave.
b)????????Slave服務器重啟后,登錄mysql
mysql>?stop?slave;
Query?OK,?0?rows?affected?(0.00?sec)
mysql>?change?master?to
->?master_host='192.168.0.3',
->?master_user='navy',
->?master_password='password',
->?master_log_file='mysql-bin.000013',
->?master_log_pos=106;
Query?OK,?0?rows?affected?(0.02?sec)
mysql>?start?slave;
Query?OK,?0?rows?affected?(0.00?sec)
mysql>?show?slave?status\G;
***************************?1.?row?***************************
Slave_IO_State:?Waiting?for?master?to?send?event
Master_Host:?192.168.240.131
Master_User:?navy
Master_Port:?3306
Connect_Retry:?60
Master_Log_File:?mysql-bin.000013
Read_Master_Log_Pos:?98
Relay_Log_File:?alan-relay-bin.000002
Relay_Log_Pos:?235
Relay_Master_Log_File:?mysql-bin.000013
Slave_IO_Running:?Yes
Slave_SQL_Running:?Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
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:?98
Relay_Log_Space:?235
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
1?row?in?set?(0.01?sec)
ERROR:?No?query?specified
當這個參數(shù)都為yes時,證明主從復制成功
Slave_IO_Running:?Yes???Slave_SQL_Running:?Yes
設置只讀:
Alter?database?dbname?set?READ_ONLY
恢復讀寫:
Alter?DATABASE?db_name?SET?READ_WRITE
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的mysql主从复制运维_Mysql主从复制配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu11.10 mysql_Ub
- 下一篇: mysql5.5.3下载_MySQL5.