posts - 431,  comments - 344,  trackbacks - 0

一. 安装包选择:

      mysql-5.0.19.tar.gz

二. 安装环境:

主服务器:   192.168.0.201

从服务器:   192.168.0.00

三.主服务器配置:

Ø         建立用户
grant replication slave on *.* to user001@192.168.0.200 identified by ‘111111′

Ø         编辑配置文件/etc/my.cnf
server-id = 1
log-bin=mysql-bin
binlog-do-db=test
binlog-ignore-db=mysql

 

注:

 # grant replication slave on *.* to ‘用户名’@'主机’ identified by ‘密码’;
# binlog-do-db=需要备份的数据库名,可写多行
# binlog-ignore-db=不需要备份的数据库名,可写多行

       # 可在B Slave上做连接测试: mysql -h 192.168.0.200 -u test -p

四.从服务器配置:

Ø        编辑/etc/my.cnf

server-id=2
server-id=2       记得是两个???
log-bin=mysql-bin
master-host=192.168.0.201
master-user=user001
master-password=111111
master-port=3306
replicate-do-db=test
replicate-do-db=test1
# replicate-do-db=test  需要备份的数据库名
# replicate-ignore-db=mysql 忽略的数据库
# master-connect-retry=60 如果从服务器发现主服务器断掉,重新连接的时间差(秒)

先手动同步一下主从服务器中要备份的数据库,再重启主,从服务器。

五.验证是否配置正确:

     # mysql>  slave start;

     # mysql>  show slave status\G;

*************************** 1. row ***************************

             Slave_IO_State: Waiting for master to send event

                Master_Host: 192.168.0.201

                Master_User: repluser1

                Master_Port: 3306

              Connect_Retry: 60

            Master_Log_File: mysql-bin.000045

        Read_Master_Log_Pos: 212

             Relay_Log_File: sky-relay-bin.000054

              Relay_Log_Pos: 235

      Relay_Master_Log_File: mysql-bin.000045

           Slave_IO_Running: Yes

          Slave_SQL_Running: Yes

            Replicate_Do_DB: test,test1

        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: 212

            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.00 sec)

确如如下行一致:
Waiting for master to send event
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

其他: ++主服务器上的相关命令
show master status
show slave hosts
show logs
show binlog events
purge logs to ‘log_name’
purge logs before ‘date’
reset master(老版本flush master)
set sql_log_bin=

++从服务器上的相关命令
slave start
slave stop
SLAVE STOP IO_THREAD //此线程把master段的日志写到本地
SLAVE start IO_THREAD
SLAVE STOP SQL_THREAD //此线程把写到本地的日志应用于数据库
SLAVE start SQL_THREAD
reset slave
SET GLOBAL SQL_SLAVE_SKIP_COUNTER
load data from master
show slave status(SUPER,REPLICATION CLIENT)
CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,MASTER_USER=, MASTER_PASSWORD= //动态改变master信息
PURGE MASTER [before ‘date’] 删除master端已同步过的日志

++产生了mysql-bin.00000x文件可以删除

 

附一: mysql无法启动:

# /usr/local/mysql//bin/mysqld_safe --user=mysql --log-error=err.txt

# more err.txt 根据里面的提示信息进行判断分析

 

附二: 解决mysql“Access denied for user 'root'@'localhost'”

mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
修改root用户的密码:
# mysqladmin -uroot -p password 'newpassword' -

文章出处:http://www.diybl.com/course/6_system/linux/Linuxjs/2008622/127458.html

posted on 2009-04-15 14:02 周锐 阅读(357) 评论(0)  编辑  收藏 所属分类: MySQL

只有注册用户登录后才能发表评论。


网站导航: