操作系統:Ubuntu11.04 Server
1、修改 mysql1 master 的配置文件
nano /etc/mysql/my.cnf
找到 bind-address = 127.0.0.1
改爲 bind-address = 0.0.0.0
找到
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
去掉 註釋符號
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
default-character-set = utf8 #新加上的爲了保持編碼一至防止出錯
binlog-do-db = 需要同步的數據庫
重新啓動mysql
2、修改 mysql2 服務器slave的 my.cnf配置文件
找到 bind-address = 127.0.0.1
替換 bind-address = 0.0.0.0
找到
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
把 註釋符號去掉 改爲如下
server-id = 2
master-host = 192.168.6.4
master-user = ludy
master-password = ypmwbg
master-port = 3306
log_bin = /var/log/mysql/mysql-bin.log
log-slave-updates
skip-slave-start
配置完後 重新啓動mysql
3然後進入 mysql1 master 服務器
mysql -u root -p密碼
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 106 | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
爲slave登錄開放登陸權限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'ip地址' IDENTIFIED BY '密碼' WITH GRANT OPTION;
記錄下來以後 進入 mysql2 slave mysql
slave stop
change master to master_host='IP地址',master_port=端口號,master_user='用戶名',master_password='密碼',master_log_file='mysql-bin.000001' ,master_log_pos=106;
slave start
show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.6.4
Master_User: ludy
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 181
Relay_Log_File: mysqld-relay-bin.000003
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000001
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: 181
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)
Slave_IO_Running: Yes
Slave_SQL_Running: Yes