Mariadb数据库主从复制同步配置过程实例

目录
  • 一、环境规划
  • 二、Mariadb的主从复制介绍
    • 1.主从复制简介
    • 2.半同步复制介绍
    • 3.主从复制原理图
  • 三、安装Mariadb
    • 1.配置yum仓库
    • 2.检查yum仓库
    • 3.安装mariadb
    • 4.启动mariadb服务
    • 5.从节点安装mariadb
  • 四、mariadb主库配置
    • 1.mariadb的初始化
    • 2.修改主库配置文件
    • 3.重启mariadb服务
  • 五、mariadb从库配置
    • 1.修改从库node01节点的server.cnf文件
    • 2.修改从库node02节点的server.cnf文件
    • 3.重启node01和node02的mariadb服务
  • 六、查看mariadb主库状态
    • 1.创建数据库用户
    • 2.查看数据库用户信息
    • 3.查看主库状态
    • 4.查看mysql-bin日志文件
    • 5.gtid查询
  • 七、启动从库
    • 1.从库设置主库的gtid
    • 2.连接主库
    • 3.启动从库
    • 4.查询从库状态
  • 八、测试主从同步
    • 1.主库写入数据
    • 2.主库查看数据表
    • 3.从库查看数据表

一、环境规划

hostname IP地址 系统版本 角色
master 192.168.3.171 centos 7.6 主节点
node01 192.168.3.172 centos 7.6 从节点
node02 192.168.3.173 centos 7.6 从节点

二、Mariadb的主从复制介绍

1.主从复制简介

主从同步使得数据可以从一个数据库服务器复制到其他服务器上,在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave)。

2.半同步复制介绍

半同步复制是解决主库数据挂掉,从库数据不一致的问题。 解决方法:半同步复制,半同步复制场景中,master会监视所有的slave,确保其中至少一台数据完全同步成功,master才会返回客户端信息,此数据写成功。

3.主从复制原理图

三、安装Mariadb

1.配置yum仓库

3个节点都安装Mariadb数据库

[root@master yum.repos.d]# cat mariadb.repo
# MariaDB 10.6 CentOS repository list - created 2021-12-27 11:21 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.6/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=0
 sed -i 's#//mirrors.xtom.com.hk#//mirrors.ustc.edu.cn#g' /etc/yum.repos.d/mariadb.repo

2.检查yum仓库

[root@master yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                              repo name                                                             status
mariadb                                                              MariaDB                                                               enabled: 96
repolist: 96

3.安装mariadb

yum -y install mariadb-server

4.启动mariadb服务

[root@master yum.repos.d]# systemctl start mariadb
[root@master yum.repos.d]# systemctl enable  mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@master yum.repos.d]#

5.从节点安装mariadb

如上步骤安装即可。

四、mariadb主库配置

1.mariadb的初始化

[root@master ~]# mariadb-secure-installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
 ... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] n
 ... skipping.
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@master ~]#

2.修改主库配置文件

[root@master ~]# grep -Ev "^$|^#" /etc/my.cnf.d/server.cnf
[server]
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
server_id = 12    #  一组主从组里的每个id必须是唯一值。推荐用ip位数
log-bin= mysql-bin # 二进制日志,后面指定存放位置。如果只是指定名字,默认存放在/var/lib/mysql下
lower_case_table_names=1 # 不区分大小写
binlog-format=ROW    # 二进制日志文件格式
log-slave-updates=True    # slave更新是否记入日志
sync-master-info=1    # 值为1确保信息不会丢失
slave-parallel-threads=3 #同时启动多少个复制线程,最多与要复制的数据库数量相等即可
binlog-checksum=CRC32    # 效验码
master-verify-checksum=1    # 启动主服务器效验
slave-sql-verify-checksum=1   # 启动从服务器效验
[galera]
[embedded]
[mariadb]
[mariadb-10.6]
[root@master ~]#

3.重启mariadb服务

[root@master ~]# systemctl restart mariadb
[root@master ~]#

五、mariadb从库配置

1.修改从库node01节点的server.cnf文件

[root@node01 ~]# cat  /etc/my.cnf.d/server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
server_id=15
#log-bin= mysql-bin #log-bin是二进制文件
relay_log = relay-bin    # 中继日志, 后面指定存放位置。如果只是指定名字,默认存放在/var/lib/mysql下
lower_case_table_names=1
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.6 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.6]

2.修改从库node02节点的server.cnf文件

[root@node02 ~]# cat  /etc/my.cnf.d/server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
server_id=16
#log-bin= mysql-bin #log-bin是二进制文件
relay_log = relay-bin    # 中继日志, 后面指定存放位置。如果只是指定名字,默认存放在/var/lib/mysql下
lower_case_table_names=1
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.6 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.6]

3.重启node01和node02的mariadb服务

systemctl restart mariadb

六、查看mariadb主库状态

1.创建数据库用户

MariaDB [(none)]>  grant replication slave, replication client on *.* to 'redhat'@'%'  identified by 'admin';
Query OK, 0 rows affected (0.025 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

2.查看数据库用户信息

MariaDB [(none)]> select user,password,host from mysql.user;
+-------------+-------------------------------------------+-----------+
| User        | Password                                  | Host      |
+-------------+-------------------------------------------+-----------+
| mariadb.sys |                                           | localhost |
| root        | invalid                                   | localhost |
| mysql       | invalid                                   | localhost |
| redhat      | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | %         |
+-------------+-------------------------------------------+-----------+
4 rows in set (0.002 sec)
MariaDB [(none)]>

3.查看主库状态

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      659 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.000 sec)
MariaDB [(none)]>

4.查看mysql-bin日志文件

[root@master ~]#  ll /var/lib/mysql/mysql-bin.index
-rw-rw----. 1 mysql mysql 38 Nov 23 23:31 /var/lib/mysql/mysql-bin.index
[root@master ~]# cat  /var/lib/mysql/mysql-bin.index
./mysql-bin.000001
./mysql-bin.000002

5.gtid查询

MariaDB [(none)]> select binlog_gtid_pos('mysql-bin.000002',659);
+-----------------------------------------+
| binlog_gtid_pos('mysql-bin.000002',659) |
+-----------------------------------------+
| 0-12-2                                  |
+-----------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]>

七、启动从库

1.从库设置主库的gtid

MariaDB [(none)]>  set global gtid_slave_pos='0-12-2';
Query OK, 0 rows affected (0.080 sec)

2.连接主库

MariaDB [(none)]>  change master to master_host='192.168.3.171',master_user='redhat',master_password='admin',master_use_gtid=slave_pos;
Query OK, 0 rows affected (0.182 sec)

3.启动从库

MariaDB [(none)]>  start slave;
Query OK, 0 rows affected (0.123 sec)

4.查询从库状态

MariaDB [(none)]> show  slave status\G
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                   Master_Host: 192.168.3.171
                   Master_User: redhat
                   Master_Port: 3306
                 Connect_Retry: 60
               Master_Log_File: mysql-bin.000002
           Read_Master_Log_Pos: 1450
                Relay_Log_File: relay-bin.000002
                 Relay_Log_Pos: 1461
         Relay_Master_Log_File: mysql-bin.000002
              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: 1450
               Relay_Log_Space: 1764
               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: 12
                Master_SSL_Crl:
            Master_SSL_Crlpath:
                    Using_Gtid: Slave_Pos
                   Gtid_IO_Pos: 0-12-7
       Replicate_Do_Domain_Ids:
   Replicate_Ignore_Domain_Ids:
                 Parallel_Mode: optimistic
                     SQL_Delay: 0
           SQL_Remaining_Delay: NULL
       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
              Slave_DDL_Groups: 3
Slave_Non_Transactional_Groups: 2
    Slave_Transactional_Groups: 0
1 row in set (0.000 sec)
MariaDB [(none)]>

八、测试主从同步

1.主库写入数据

MariaDB [(none)]> create database school;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> use school;
Database changed
MariaDB [school]> CREATE TABLE IF NOT EXISTS `student`(
    ->    `id` INT UNSIGNED AUTO_INCREMENT,
    ->    `name` VARCHAR(100) NOT NULL,
    ->    `gender` TINYINT NOT NULL,
    ->    `age` INT UNSIGNED,
    ->    `class` INT UNSIGNED,
    ->      `course` VARCHAR(100) NOT NULL,
    ->     `grade` INT UNSIGNED,
    ->    PRIMARY KEY ( `id` )
    -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.206 sec)
MariaDB [school]> insert into student ( name, gender, age, class, Course, grade ) values ( "高峰", "0", "22", "4", "英语", "100"), ( "陈林", "1", "15", "5", "化学", "99" );
Query OK, 2 rows affected (0.012 sec)
Records: 2  Duplicates: 0  Warnings: 0
MariaDB [school]> insert into student ( name, gender, age, class, course, grade ) values  ( "王明", "0", "16", "2", "数学", "88"),  ( "万易", "0", "17", "4", "地理", "79" ), ( "李依依", "1", "17", "3", "语文",  "90"  ) ;
Query OK, 3 rows affected (0.017 sec)
Records: 3  Duplicates: 0  Warnings: 0

2.主库查看数据表

MariaDB [school]> select * from school.student;
+----+-----------+--------+------+-------+--------+-------+
| id | name      | gender | age  | class | course | grade |
+----+-----------+--------+------+-------+--------+-------+
|  1 | 高峰      |      0 |   22 |     4 | 英语   |   100 |
|  2 | 陈林      |      1 |   15 |     5 | 化学   |    99 |
|  3 | 王明      |      0 |   16 |     2 | 数学   |    88 |
|  4 | 万易      |      0 |   17 |     4 | 地理   |    79 |
|  5 | 李依依    |      1 |   17 |     3 | 语文   |    90 |
+----+-----------+--------+------+-------+--------+-------+
5 rows in set (0.000 sec)
MariaDB [school]>

3.从库查看数据表

[root@node01 ~]# hostname
node01
[root@node01 ~]# mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.6.11-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select * from school.student;
+----+-----------+--------+------+-------+--------+-------+
| id | name      | gender | age  | class | course | grade |
+----+-----------+--------+------+-------+--------+-------+
|  1 | 高峰      |      0 |   22 |     4 | 英语   |   100 |
|  2 | 陈林      |      1 |   15 |     5 | 化学   |    99 |
|  3 | 王明      |      0 |   16 |     2 | 数学   |    88 |
|  4 | 万易      |      0 |   17 |     4 | 地理   |    79 |
|  5 | 李依依    |      1 |   17 |     3 | 语文   |    90 |
+----+-----------+--------+------+-------+--------+-------+
5 rows in set (0.000 sec)
MariaDB [(none)]>

以上就是Mariadb数据库主从复制同步配置过程实例的详细内容,更多关于Mariadb主从复制同步配置的资料请关注我们其它相关文章!

(0)

相关推荐

  • MariaDB的安装与配置教程

    目录 MariaDB的安装与配置 1.安装相对应的源 2.清除缓存,加载配置 3.安装mariadb 4.启动mariadb 5. 查看mariadb进程 6.MariaDB数据库初始化 7.初始化测试登陆 8.MariaDB设置utf8编码(根据实际需求添加) 9.MariaDB的简单使用 10.MariaDB数据库备份与恢复 镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 MariaDB的安装与配置 (菜鸡我是用阿里源安装的) MariaDB是MySQL的一个分支,由开源社区维护,采用

  • Mariadb远程登陆配置及问题解决

    前言: 安装过程不再赘述,直接说问题,mysql的远程连接需要解决两个问题:1.允许root用户远程连接.2.允许任意ip远程连接数据库.当然,在测试和解决问题之前,得首先保证你的数据库与远程主机之间的网络通信没有问题,简单的来说,就是互相ping通,其次,为了避免防火墙的干扰,将本地主机和数据库主机的防火墙都关闭,当然,生产环境下防火墙肯定是要打开的,并且需要额外的安全配置. 问题解决: 1.新安装的数据库默认是需要初始化的,在数据库服务启动的情况下,使用下面的命令来进行初始化. [root@

  • mariadb的主从复制、主主复制、半同步复制配置详解

    主从服务器的时间要同步,数据库版本最好是一致的,以免造成函数处理.日志读取.日志解析等发生异常. 以下三个主从复制的设置是独立的. 注意防火墙和selinux的影响. 1.简单主从复制的实现 (1)主服务器的配置 1)安装mariadb-server [root@localhost ~]# yum -y install mariadb-server 2)编辑/etc/my.cnf文件 [root@localhost ~]# vim /etc/my.cnf 在[mysqld]段的最后添加以下内容

  • MariaDB表表达式之公用表表达式(CTE)

    目录 前言 1.非递归CTE 2.递归CTE 2.1 语法 2.2 递归CTE示例(1) 2.2 递归CTE示例(2) 2.2 递归CTE示例(3) 总结 前言 公用表表达式(Common Table Expression,CTE)和派生表类似,都是虚拟的表,但是相比于派生表,CTE具有一些优势和方便之处. CTE有两种类型:非递归的CTE和递归CTE. CTE是标准SQL的特性,属于表表达式的一种,MariaDB支持CTE,MySQL 8才开始支持CTE. 1.非递归CTE CTE是使用WIT

  • centos7 mariadb主从复制配置搭建详解步骤

    花了小一天的时间,终于实现了centos7 mariadb主从复制配置搭建,下面记录一下过程 环境: 虚拟机:vm8; centos7 版本:7.2.1511; mariadb 版本:centos7.2内置的 主库服务器: 10.69.5.200,CentOS 7,MariaDB 10已安装,有数据. 从库服务器1: 10.69.5.201,CentOS 7,MariaDB 10已安装,无应用数据. 主服务器配置 以下操作在主服务器192.168.71.151的/etc/my.cnf上进行. 1

  • Mariadb数据库主从复制同步配置过程实例

    目录 一.环境规划 二.Mariadb的主从复制介绍 1.主从复制简介 2.半同步复制介绍 3.主从复制原理图 三.安装Mariadb 1.配置yum仓库 2.检查yum仓库 3.安装mariadb 4.启动mariadb服务 5.从节点安装mariadb 四.mariadb主库配置 1.mariadb的初始化 2.修改主库配置文件 3.重启mariadb服务 五.mariadb从库配置 1.修改从库node01节点的server.cnf文件 2.修改从库node02节点的server.cnf文

  • MySQL数据库主从同步实战过程详解

    本文实例讲述了MySQL数据库主从同步实战过程.分享给大家供大家参考,具体如下: 接上一篇:MySQL数据库入门之备份数据库 安装环境说明 系统环境: [root@~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@~]# uname -r 2.6.32-431.el6.x86_64 数据库: 由于是模拟环境,主从库在同一台服务器上,服务器IP地址192.168.1.7 主库使用3306端口 从库使用3307端口 数据库数据目

  • mysql数据库 主从复制的配置方法

    MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维 护日志文件的一个索引以跟踪日志循环.当一个从服务器连接到主服务器时,它通知主服务器从服务器在日志中读取的最后一次成功更新的位置.从服务器接收从那 时起发生的任何更新,然后封锁并等待主服务器通知下一次更新. 为什么使用主从复制? 1.主服务器/从服务器设置增加了健壮性.主服务器出现问题时,你可以切换到从服务器作为备份. 2.通过在主服务器和从服务器之间切分处理

  • InnoDB引擎数据库主从复制同步新的分享

    近期将公司的MySQL架构升级了,由原先的一主多从换成了DRBD+Heartbeat双主多从,正好手上有一个电子商务网站新项目也要上线了,用的是DRBD+Heartbeat双主一从,由于此过程还是有别于以前的MyISAM引擎的,所以这里也将其心得归纳总结了一下: 1)MySQL的replication过程是一个异步同步的过程,并非完全的主从同步,所以同步的过程中是有延迟的,如果做了读写分离的业务的话,建议也要监控此延迟时间: 2)MySQL的master与slave机器记得server-id要保

  • linux下mysql数据库单向同步配置方法分享

    又叫做主从复制,是通过二进制日志文件完成的,注意:mysql 数据库的版本,两个数据库版本要相同 系统环境: 主服务器master IP: 192.168.0.88 从服务器slave IP: 192.168.0.99 单向同步 注意要点 1.只需要把需要同步的数据库备份传到从数据库上,其它任何东西都不需要 2.在从库上还原数据库时,一定先要建了同名数据库,否则还原会提示错误 3.在制定更新点时,一定要在同步进程还没启动前操作 主服务器上配置 对my.cnf进行修改需要重启动数据库设置才会生效,

  • MariaDB数据库的外键约束实例详解

    外键 外键的用途是确保数据的完整性.它通常包括以下几种: 1 实体完整性,确保每个实体是唯一的(通过主键来实施) 2 域完整性,确保属性值只从一套特定可选的集合里选择 3 关联完整性,确保每个外键或是NULL(如果允许的话)或含有与相关主键值相配的值 1.什么是外键约束 与主键约束不同,创建外键约束不会自动创建对应的索引. 但是由于以下原因,对外键手动创建索引通常是有用的: 当在查询中组合相关表中的数据时,经常在联接条件中使用外键列,方法是将一个表的外键约束中的一列或多列与另一个表中的主键列或唯

  • Spring数据库多数据源路由配置过程图解

    项目中需要根据不同业务进行分库,首先是将业务不同业务映射到不同过的数据库( biz --> db,可能存在多对一情况), 查看springjdbc源码发现AbstractRoutingDataSource类作为一个数据源路由抽象类,可以担当这个事情,其设计思想也比较简单, 首先将多个数据源的映射关系自己维护完成后注入进来,然后自己定义一个路由规则,重点部分见代码: 首先可以看到该类是一个抽象类,重点关注变量targetDataSource和resolvedDataSources. 其中targe

  • MySQL数据库InnoDB引擎主从复制同步经验总结

    近期将公司的MySQL架构升级了,由原先的一主多从换成了DRBD+Heartbeat双主多从,正好手上有一个电子商务网站新项目也要上线了,用的是DRBD+Heartbeat双主一从,由于此过程还是有别于以前的MyISAM引擎的,所以这里也将其心得归纳总结了一下: 1)MySQL的replication过程是一个异步同步的过程,并非完全的主从同步,所以同步的过程中是有延迟的,如果做了读写分离的业务的话,建议也要监控此延迟时间: 2)MySQL的master与slave机器记得server-id要保

  • mysql主从复制配置过程

    主库配置 1. 配置mysql vim /etc/my.cn # 在文件中增加以下内容 server-id=1 # 保证server id唯一 log-bin = /var/lib/mysql/mysql-bin.log binlog-do-db = db1 binlog-do-db = db2 其中db1和db2是计划进行主从复制的库,如果有多个,写多行即可.配置完毕后,重启数据库: service mysqld restart 2. 添加复制用户 通过phpmyadmin,添加新用户,并授予

随机推荐