Mysql主从同步及其读写分离的实现过程
作者 佚名技术
来源 Linux系统
浏览
发布时间 2012-03-27
|
Mysql主从同步及其读写分离的实现过程
环境:CentOS release 5.2 、mysql-5.1.55.tar.gz、mysql-proxy-0.8.1-linux-rhel5-x86-32bit.tar.gz
测试机:172.16.10.11:mysql proxy 及其mysql主数据库
172.16.10.12:mysql从数据库
1.编译安装mysql:
a yum安装mysql所需要的环境
#yum install make gcc gcc-c libxml2 libxml2-devel libmcrypt libmcrypt-devel libtool-ltdl apr apr-* ncurses ncurses-*
b.安装mysql
#/usr/sbin/groupadd mysql
#/usr/sbin/useradd mysql –g mysql
在执行./configure 之前,先执行:
# autoreconf --force --install
# libtoolize --automake --force
# automake --force --add-missing
#./configure --prefix=/opt/mysql --localstatedir=/opt/mysql/data/ --with-server-suffix=-enterprise-gpl --without-debug --with-big-tables --with-extra-charsets=all --with-pthread --enable-thread-safe-client --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-ndb-debug --with-plugins=innobase
#Make
#Make install
初始化
#scripts/mysql_install_db –-user=mysql (一定要添加)
改权限、主配置文件、环境变量
#chown -R mysql.mysql /opt/mysql/
# cp support-files/my-medium.cnf /etc/my.cnf
# chmod 750 /opt/mysql –R //-R : 对目前目录下的所有档案与子目录进行相同的权限变更
# chgrp mysql /opt/mysql -R
启动mysql
#/opt/mysql/bin/mysqld_safe –user=mysql &
到此mysql服务器的安装就结束了!
备:在两台服务器上均安装mysql数据库
2 mysql主从同步配置过程
在主服务器上:
#vi /etc/my.cnf
修改或添加以下条目
Log-bin=master-bin //修改
Log-bin-index=master-bin.index //添加
Server-id=1
重启mysql数据库
添加replication账号
#/opt/mysql/bin/mysql –uroot –p
Mysql>grant replication slave on *.* to ‘slave’@’172.16.10.12’ identified by ‘123456’;
Mysql>flush privileges;
查看master当前的日志文件及日志位置:
mysql> show master status;
------------------- ---------- -------------- ------------------
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
------------------- ---------- -------------- ------------------
| master-bin.000001 | 106 | | |
------------------- ---------- -------------- ------------------
在从的数据库上:
#vi /etc/my.cnf
修改或添加以下条目
log-bin=mysql-bin
relay-log=relay-log-bin //添加
relay-log-index=slave-relay-bin.index //添加
server-id=2
注:server-id不能与主服务器的相同
重启mysql服务
#/opt/mysql/bin/mysql –uroot –p
Mysql>stop slave;
Mysql>change master to master_host=’172.16.10.11’,master_port=3306,master_user=’slave’,master_password=’123456’,master_log_file=’master-bin.000001’,master_log_pos=106;
Mysql>start slave
Mysql>show slave status\G
出现如下两行
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
表示主从mysql服务器配置完成!
如果出现no,就将从数据库上述重新操作一遍"stop slave".
Mysql p |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn
为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
|