您的位置:首页 > 数据库 > MySQL

Mysql主从复制详解(二)

2011-06-03 03:28 513 查看
以下是我的实验环境:master: redhat-6.0 mysql-5.0.18slave : redhat6.0 mysql-5.0.18官方建议主从服务器数据库版本一致,master 配置确保/etc/my.cnf中有[mysqld] log-bin=mysql-bin server-id=1binlog-do-db=test #根据自己情况设定binlog-ignore-db=mysql #根据自己情况设定
还要有个用户用来复制,要有replication slavef 权限
slave配置 /etc/my.cnfbinlog-do-db=test #根据自己情况设定binlog-ignore-db=mysql #根据自己情况设定server-id=2
复制步骤:1. 首先要查看主服务器控制的二进制文件名称和pos值mysql> show master status\G*************************** 1. row *************************** File: mysql-bin.000002 Position: 98 Binlog_Do_DB: testBinlog_Ignore_DB: mysql1 row in set (0.00 sec)这2个值很重要,由于我是实验环境没有实时数据,这2个值不会变。其他情况下应该使用mysql>flush tables with read lock; 使表只读备份数据库mysqldump 或者 tar… ,拷贝到从服务器上并解压mysql>unlock tables;2. 从服务器上启动服务/usr/local/mysql/bin/mysqld_safe –user=mysql –skip-slave-start & 复制选项:mysql> chage master to>master_host=’192.168.0.6’,>master_port=3306,>master_user=’repl’,>master_password=’123456’,>master_log_file= ‘mysql-bin.000002’ >master_log_pos=98;然后启动复制 mysql>slave start ;如果看到下面的值,表示配置成功 Slave_IO_Running: Yes Slave_SQL_Running: Yes
可是我的情况是Slave_IO_Running: NO这说明根本没有从主服务器上或得二进制文件在网上找了半天,大多数内容都是一样的,只好自己找原因了,在数据库上层目录中有些日志文件,从中找到了解决办法(这个日志slave.site.err)110603 1:22:46 [ERROR] Slave I/O thread: error connecting to master 'repl@192.168.0.6:3306': Error: 'Host '192.168.0.7' is not allowed to connect to this MySQL server' errno: 1130 retry-time: 60 retries: 86400问题是主服务器不允许192.168.0.7这个主机连接解决办法mysql> update user set host=’192.168.0.7 ’ where user=’repl’;mysql>flush privileges;从服务器上执行复制mysql>slave start ;mysql> show slave status\G*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: rhel6-test.site Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 98 Relay_Log_File: slave-relay-bin.000003 Relay_Log_Pos: 235 Relay_Master_Log_File: mysql-bin.000002 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: 01 row in set (0.00 sec)单向复制配置成功更详细的说明请查看官方文档http://dev.mysql.com/doc/refman/5.1/zh/index.html[align=left][/align]本文出自 “Fight For Free & Union” 博客,请务必保留此出处http://renpeng.blog.51cto.com/623897/580246
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: