我使用的是mysql-5.1.33.tg.gz
下面是我的编译参数。
# ./configure --prefix=/usr/local/mysql-5.1.33 --without-comment --without-debug --with-ssl --with-charset=gbk --with-extra-charsets=gb2312,utf8 --enable-thread-safe-client --enable-local-infile --enable-assembler --with-big-tables --with-plugins=innobase
# make
# make install
# ln -s /usr/local/mysql-5.1.33 /usr/local/mysql
保持编译默认配置,启动数据库,为了方便起见可以把mysql的目录写到PATH变量中.
# export PATH=$PATH:/usr/local/mysql/bin
关于更详细的安装过程请参照:
二、修改主数据库的配置文件
[主服务器]
eth1:192.168.254.2
参照http://dev.mysql.com/doc/refman/5.1/en/replication-howto-masterbaseconfig.html,binlog_format=mixed参数不是必须的,可以注
# vim /etc/my.cnf
[mysqld]
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
binlog_format=mixed
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# service mysqld start
在主数据库服务器上,进入mysql下,配置专用的二进制日志传输用户.
也可参照http://dev.mysql.com/doc/refman/5.1/en/replication-howto-repuser.html只使用replication slave权限即可。
mysql> flush privileges;
mysql> exit;
# mysql -u slave -h 192.168.254.2 -pslavepass
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.33-log Source distribution
请特别注意在此期间最好没有任何写入操作。可以在mysql下锁定数据库的写:
mysql> FLUSH TABLES WITH READ LOCK;
注意如果在my.cnf中包含了主服务器的信息,这一步就不是必须。
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 332 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> UNLOCK TABLES;
[从服务器]
eth1:192.168.254.3
[mysqld]
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
server-id = 2
#
# 下面都是主服务器的信息,实际我们也可以在服务器启动后,实时地通过mysql命令来修改它们,都不是必须的。
# The replication master for this slave - required
master-host = 192.168.254.2
#
# The username the slave will use for authentication when connecting
# to the master - required
master-user = slave
#
# The password the slave will authenticate with when connecting to
# the master - required
master-password = slavepass
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = 3306
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# service mysqld start
# mysql < dbbackup*.sql
mysql> UNLOCK TABLES;
同步数据:
mysql> CHANGE MASTER TO MASTER_HOST='ServerIP/FQDN', MASTER_USER='ReplClient', MASTER_PASSWORD='ClientPassword',
例如我是直接执行:
mysql> CHANGE MASTER TO MASTER_HOST='192.168.254.2', MASTER_USER='slave',
Query OK, 0 rows affected (0.02 sec)
启动同步
mysql> start slave;
查看状态
主:
mysql> show master status;
从:
mysql> show slave status;
mysql> start slave;
停止:
mysql> stop slave;