操作系统: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