上次给大家介绍了mysql 5.1主从搭建配置教程,这次我们来实现mysql 5.5的主从复制,其实大体上配置是差不多的,只有点细微的差别.
系统:centos 5.x
需要的软件包:mysql-5.5.33.tar.gz
环境准备:
服务器a:192.168.10.151 (主)
服务器b:192.168.10.152 (从)

1.安装前准备
wget http://mysql.llarian.net/Downloads/MySQL-5.5/mysql-5.5.33.tar.gz
yum -y install gcc gcc-c++ libtool-libs autoconf freetype-devel gd libjpeg-devel
libpng-devel libxml2-devel ncurses-devel zlib-devel zip unzip curl-devel wget crontabs
file bison cmake patch mlocate flex diffutils automake make kernel-devel cpp
readline-devel openssl-devel vim-minimal glibc-devel glib2-devel
bzip2-devel e2fsprogs-devel libidn-devel gettext-devel expat-devel
libcap-devel libtool-ltdl-devel pam-devel pcre-devel libmcrypt-devel

2.在服务器a上安装mysql
tar zxf mysql-5.5.33.tar.gz && cd mysql-5.5.33
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=complex -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1

make
make install

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cd support-files/
cp my-medium.cnf /etc/my.cnf
cp -f mysql.server /etc/rc.d/init.d/mysqld
mkdir /var/lib/mysql
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib/mysql
/usr/local/lib
EOF
ldconfig

如果你是在64位机器上的话,那你就执行下面这个命令:
ln -s /usr/local/mysql/lib/mysql /usr/lib64/mysql

如果你是在32位机器上的话,那就执行下面的命令:
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

然后再执行:
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
ln -s /usr/local/mysql/bin/mysqldump /usr/bin
service mysqld start
mysqladmin -u root password 'password'

当然如果大家觉得编译安装mysql很麻烦的话,那么可以去看看这篇文章安装mysql5.5二进制包.

服务器b安装mysql配置跟服务器a一样,这里就不说了.

3.配置主从
在服务器a上:
vi /etc/my.cnf
[mysqld]
log-bin=master-bin
log-bin-index=master-bin.index
server-id = 1
innodb_file_per_table = 1
binlog_format=mixed

授权复制用户:
mysql -u root -p
grant replication slave on *.* to 'dbmysql'@'%' identified by '123456';
flush privileges;

重启mysql
service mysqld restart

在服务器b上:
vi /etc/my.cnf
[mysqld]
relay-log = relay-log
relay-log-index = relay-log.index
server-id = 2
innodb_file_per_table = 1
binlog_format=mixed

然后重启mysql
service mysqld restart

服务器b连接连接主服务器并复制
先在服务器a上查看master的状态
mysql> show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000001 | 107 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

然后在服务器b上进行连接
mysql> change master to master_host='192.168.10.151',master_user='dbmysql',maste
r_password='123456',master_log_file='master-bin.000001',master_log_pos=107;

查看一下slave状态
mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.10.151
Master_User: dbmysql
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 107
Relay_Log_File: localhost-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: No
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: 107
Relay_Log_Space: 107
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_(www.111cn.net)CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
1 row in set (0.00 sec)

启动slave再查看
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 192.168.10.151
Master_User: dbmysql
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 107
Relay_Log_File: localhost-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Connecting
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: 107
Relay_Log_Space: 107
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2003
Last_IO_Error: error connecting to master 'dbmysql@192.168.10.151:3306' - retry-time: 60 retries: 86400
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
1 row in set (0.00 sec)

看到上面错误了没,说明mysql主和从服务器的防火墙没有开放3306端口,去服务器a和服务器b上把3306端口打开,再来查看mysql从的状态
mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.10.151
Master_User: dbmysql
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 107
Relay_Log_File: relay-log.000011
Relay_Log_Pos: 254
Relay_Master_Log_File: master-bin.000001
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: 107
Relay_Log_Space: 404
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
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)

好了,可以看到Slave_IO_Running和Slave_SQL_Running都是yes了,下面也没有error提示了.

4.验证
在mysql主上创建个数据库
mysql> create database emlog;
Query OK, 1 row affected (0.01 sec)

再在mysql从上查看是否有这个数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| emlog |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.02 sec)

可以看到已经同步复制过来了,mysql主从搭建成功.
from:http://www.111cn.net/database/mysql/52862.htm

mysql 5.5数据库主从配置步骤详解的更多相关文章

  1. MySQL数据库安装配置步骤详解

    MYSQL的安装 1.打开下载的mysql安装文件mysql-5.5.27-win32.zip,双击解压缩,运行“setup.exe”. 2.选择安装类型,有“Typical(默认)”.“Comple ...

  2. (转载) IBM DB2数据库odbc配置步骤详解

    [IT168 技术] 首先安装IBM DB2 odbc driver 1):可以单独下载DB2 Run-Time Client,大约(86.6m),安装后则odbc驱动程序安装成功.下载地址:ftp: ...

  3. C#自制Web 服务器开发:mysql免安装版配置步骤详解分享

    mysql免安装版配置步骤详解分享 1.准备工作 下载mysql的最新免安装版本mysql-noinstall-5.1.53-win32.zip,解压缩到相关目录,如:d:\ mysql-noinst ...

  4. Oracle 11g客户端在Linux系统上的配置步骤详解

    Oracle 11g客户端在Linux系统上的配置步骤详解 2011-07-26 10:47 newhappy2008 CSDN博客 字号:T | T 本文我们主要介绍了Oracle 11g客户端在L ...

  5. MySQL主从配置图文详解

    #环境配置#master IP:192.168.46.137 slave IP:192.168.46.138 database:v1 1.在两台机器,分别安装mysql数据库,分别添加远程连接权限 2 ...

  6. IntelliJ IDEA 2017 JDK Tomcat Maven 配置步骤详解(一)

    要求   配置 Java基础环境(实际上应该在虚拟机linux环境下 安装CentOS 7,但是我这电脑实在承受不住了) 安装 开发工具 IntelliJ IDEA 2017.1 第一部分: JDK ...

  7. Lucene配置步骤详解

    Lucene配置步骤说明: 1.搭建环境: 2.创建索引库: 3搜索索引库. Lucene配置步骤: 第一部分:搭建环境(创建环境导入jar包) 前提:已经创建好了数据库(直接导入book.sql文件 ...

  8. oracle数据库tns配置方法详解

    TNS简要介绍与应用 Oracle中TNS的完整定义:transparence Network Substrate透明网络底层,监听服务是它重要的一部分,不是全部,不要把TNS当作只是监听器. TNS ...

  9. mysql在win系统dos 安装版配置步骤详解

    1.准备工作 下载mysql的最新免安装版本mysql-noinstall-5.1.53-win32.zip,解压缩到相关目录,如:d:\ mysql-noinstall-5.1.53-win32.这 ...

随机推荐

  1. Dictionary应用

    using System; using System.Collections.Generic; using System.Data; using System.Web; using System.We ...

  2. Selenium2(WebDriver)总结(五)---元素操作进阶(常用类)

    1.Alert类 Alert是指windows弹窗的一些操作,需要new一个Alert类 driver.switchTo().alert():切换到alert窗口 alert.getText():取得 ...

  3. SAN和虚拟化,NUMA等

    Virtual Networking Best Practices Following are the vSphere networking best practices: •Separate vir ...

  4. shell语法使用

    这两天初次接触shell编程,所谓shell编程其实就是用一定的语法将各种基本的命令组合起来,让shell程序去解释执行.如果对windows的dos有了解,可以这样理解,其实shell脚本文件和.b ...

  5. MySql8.0数据库链接报错The driver has not received any packets from the server

    1.我使用MySql数据库8.0版本,然后驱动改成了 jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306 ...

  6. java sm4国密算法加密、解密

      java sm4国密算法加密.解密 CreationTime--2018年7月5日09点20分 Author:Marydon 1.准备工作 所需jar包: bcprov-jdk15on-1.59. ...

  7. http://blog.csdn.net/u011277123/article/details/53665302

    导读:Oracle中,除Exp命令可进行一般的全库.全用户导出外,还可通过增加相关参数条件实现对部分库表或数据的导出. 测试环境 在如下图的测试环境中,当前登录用户名为“jck”,该用户下有200多张 ...

  8. Hibernate第一次学习总结

    Hibernate概述 是一款方便应用操作数据库的中间件,使应用直接通过操作Java对象来操作数据库. 实现了ORM模型,包括:数据库表与JAVA对象的映射,表关联与Java对象关系的映射. 实现了O ...

  9. 转载:mysql添加用户、删除用户、授权、修改密码

    mysql添加用户.删除用户.授权.修改密码等 MySql中添加用户,新建数据库,用户授权,删除用户,修改密码1.新建用户. //登录MYSQL @>mysql -u root -p @> ...

  10. redis配置笔记

    #cd /opt#tar -zxvf redis-4.0.6.tar.gz#cd redis-4.0.6#make #cd src#make install PREFIX=/usr/local/red ...