mysql上主从服务器配置

mysql主从是非常常见的应用,可以实现简单的负载均衡(一定意义上).主要用途是减轻主库负载,通常主库只负责更新类(insert,update,delete)操作.辅库负责读操作.

1 登录主库并为辅库建立一个用户(如 hbl 主机:192.168.0.3).

grant replication slave on *.* to ‘hbl’@'192.168.0.3′ identified by ‘hbl’; (在MySQL 4.0.2以前,用 FILE 权限来代替 REPLICATION SLAVE)

2 编辑 主库 my.cnf文件.

 bash |  copy code |? 
vi /etc/my.cnf

 mysql |  copy code |? 
#指定一个server-id 不能和已有的重复~
server-id=1
log-bin=mysql-bin
#需要备份的数据库,可多行
binlog-do-db=dpd_wenxue
#不需要备份的数据库 ,可多行
binlog-ignore-db=mysql

3 编辑辅库 my.cnf文件

 mysql |  copy code |? 
server-id=2
log-bin=mysql-bin
#自定主库ip
master_host=192.168.0.10
master_user=dpd_wenxue
master_password=dpd_wenxue
master_port=3306
 #需要备份的数据库,可多行    要和主库保持一致                                                                             
replicate_do_db=dpd_wenxue
#不需要备份的数据库 ,可多行 要和主库保持一致
replicate_ignore_db=dpd_wenxue

3 登录验证
在辅库执行
show slave status;
返回中有以下两行表示配置成功:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
如果有这行
Slave_IO_State: Waiting for master to send event
需要启动 slave , start slave 即可.

注:在此次配置中,碰到几个问题
1 在配置文件之前,可以在mysql中通过命令
change master to master_host =…..,结果导致 master的Master_Log_File 和slave的不一样.导致同步失败.在mysql命令行下输入的change master 是临时的.
2 由于配置辅库时,主库进行了更改,导致slave同步时出问题.最后的解决办法是
change master to Read_Master_Log_Pos 指到主库的position上(可以在主库上 show master status看到).

Posted in mysql | Tags: ,

0 Comments.

Leave a Reply

[ Ctrl + Enter ]

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Get Adobe Flash playerPlugin by wpburn.com wordpress themes