mariadb主从同步

本文是搭建的mariadb-10.0.17版本的下载地址:https://downloads.mariadb.org/interstitial/mariadb-10.0.17/source/mariadb-10.0.17.tar.gz/from/http%3A//ftp.hosteurope.de/mirror/archive.mariadb.org/?serve

master:192.168.1.166

slave:192.168.1.165

1.创建mysql普通账号,设置数据库存储数据的目录,设置权限

[[email protected] ~]# groupadd -r mysql

[[email protected]~]# useradd -r -g mysql -s /sbin/nologin mysql

[[email protected]~]# mkdir -p /data/mydata

[[email protected]~]# chown -R mysql:mysql /data

2.安装数据库依赖软件包

[[email protected]~]# yum install -y gcc gcc-c++ make cmake ncurses ncurses libxml2 libxml2-developenssl-devel bison bison-devel ncurses-devel

3.上传mariadb包,解压,编译安装。

[[email protected] ~]# tar zxvf mariadb-10.0.17.tar.gz

[[email protected] mariadb-10.0.17]# cmake-DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/data/mydata-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system-DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci

[[email protected] mariadb-10.0.17]# make&& make install

4.复制数据库启动脚本到/etc/init.d/mysqld目录下,修改/etc/my.cnf配置文件。

[[email protected]]# cd /app/mysql/

[[email protected]]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[[email protected]]# chmod +x /etc/rc.d/init.d/mysqld

[[email protected]]# cp support-files/my-large.cnf /etc/my.cnf

5.初始化数据库,启动数据库

[[email protected]]# scripts/mysql_install_db --user=mysql --datadir=/app/mysql/data

[[email protected]]#mkdir log

[[email protected]]#service mysqld start

6.数据库的系统变量

[[email protected] mysql]# vim/etc/profile.d/mysqld.sh

export PATH=$PATH:/usr/local/mysql/bin

[[email protected] mysql]# source/etc/profile.d/mysqld.sh

[[email protected] mysql]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 148

Server version: 5.5.5-10.0.17-MariaDB-logSource distribution

Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘to clear the current input statement.

mysql>

7.master192.168.1.166里/etc/my.cnf 如下

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

port = 3306

socket = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 256M

max_allowed_packet = 4690M

table_open_cache = 16

sort_buffer_size = 64M

read_buffer_size = 32M

read_rnd_buffer_size = 256M

myisam_sort_buffer_size = 1024M

thread_cache_size = 8

query_cache_size= 128M

log-error=/app/mysql/log/alert.log

slow_query_log_file=/app/mysql/log/slow.log

general_log_file=/app/mysql/log/general.log

datadir = /app/mysql/data

log-bin=mysql-bin

binlog_format=mixed

server-id = 1

[mysqldump]

quick

max_allowed_packet = 4690M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 128M

sort_buffer_size = 128M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

8.slave192.168.1.165里/etc/my.cnf

port = 3306

socket = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

log-error=/app/mysql/log/alert.log

slow_query_log_file=/app/mysql/log/slow.log

general_log_file=/app/mysql/log/general.log

thread_concurrency = 8

datadir = /data/mydata

log-bin=mysql-bin

binlog_format=mixed

server-id = 2

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 128M

sort_buffer_size = 128M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

9.在master数据库上授权    mysql

mysql> GRANT ALL PRIVILEGES ON *.* TO‘root‘@‘192.168.1.% IDENTIFIED BY ‘passwd‘ WITH GRANT OPTION;

mysql>flush privileges;

mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB |Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000008 |     2890 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

10.在从slave mysql

mysql>stop slave;

mysql> change master tomaster_host=‘192.168.1.166‘,master_user=‘root‘,master_password=‘passwd‘,master_log_file=‘mysql-bin.000008‘,master_log_pos=2890,master_connect_retry=5,master_heartbeat_period=2,Master_Port=3306;

mysql>flush privileges;

mysql>start slave;

mysql>show slave status\G

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

Slave_IO_State: Waiting formaster to send event

Master_Host: 192.168.1.166

Master_User: root

Master_Port: 3306

Connect_Retry: 5

Master_Log_File: mysql-bin.000008

Read_Master_Log_Pos: 2890

Relay_Log_File:zsxyweb3-relay-bin.000002

Relay_Log_Pos: 1198

Relay_Master_Log_File: mysql-bin.000008

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

Relay_Log_Space: 1498

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

Master_SSL_Crl:

Master_SSL_Crlpath:

Using_Gtid: No

Gtid_IO_Pos:

1 row in set (0.00 sec)

注:主要看看Slave_IO_Running: Yes Slave_SQL_Running: Yes  是否为yes

时间: 2024-10-24 00:45:57

mariadb主从同步的相关文章

MySQL(Mariadb)主从同步基础

一.准备阶段 两台linux虚拟机centos7版本,都安装了mariadb 5.5.6 进行主从同步配置: 首先防火墙要开放3306端口, 主库服务器ip:192.168.211.100 从库服务器ip:192.168.211.101 二.配置主库 1.主库上给从库ip授权 mysql>GRANT REPLICATION SLAVE ON *.* to 'rep1'@'192.168.211.101' identified by 'test123456';mysql>FLUSH PRIVIL

MariaDB、MySQL数据库主从同步

1.Mysql主从同步异步概念 异步:主服务器写完日志后立即返回同步完成消息,不受从服务器的状态和影响,mysql默认为异步工作模式 同步:主服务器写入数据到本地磁盘并记录好二进制日志,然后等从服务器发现数据发送改变再把数据同步到从服务器的日志中继并保存到二进制日志和磁盘,最后返回给主服务器同步完成的结果,因此比较影响性能. 2.同步过程: 主 服务器在可能修改数据时会把行内容记录在二进制日志中,而从服务会不停到主服务器请求数据,相当于mysql客户端,不停请求服务器的3306端口,从服 务器请

mariadb的主从同步和读写分离

前言 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品.前提两台服务器,今天就要用它来搭建多服务器的主从同步和读写分离, 两台服务的环境是:192.168.47.128 centos7 mariadb10.3192.168.47.129 centos6.5 mariadb10.3下面开始搭建: mariadb安装 1.centos7下面的安装我以前有很多教程

mariadb、redis安装配置及MySQL主从同步

今日内容 https://www.cnblogs.com/pyyu/p/9467289.html mysql博客 mysql (分支 mariadb)1.安装mariadb -yum -源码编译安装 -下载rpm安装 yum和源码编译安装的区别? 1.路径区别-yum安装的软件是他自定义的,源码安装的软件./configure --preifx=软件安装的绝对路径 2.yum仓库的软件,版本可能比较低,而源码编译安装,版本可控 3.编译安装的软件,支持第三方功能扩展./configure 这里可

mysql数据库主从同步

环境: Mater:   CentOS7.1  5.5.52-MariaDB  192.168.108.133 Slave:   CentOS7.1  5.5.52-MariaDB  192.168.108.140 1.导出主服务数据,将主备初始数据同步 master: //从master上导出需要同步的数据库信息 mysqldump -u*** -p*** --database test > test.sql //将master上的备份信息传输到slave上 scp /root/test.sq

MariaDB主从搭建与测试

(一) 安装相同版本的MariaDB. 这里我使用yum 安装1) master:rpm --import http://yum.mariadb.org/RPM-GPG-KEY-MariaDB echo '# MariaDB 10.0 CentOS repository list - created 2014-03-15 08:00 UTC# http://mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http

Linux服务器集群架构部署搭建(六)数据库服务器MySQL编译安装及主从同步配置(1)

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 作者:燁未央_Estelle声明:测试学习,不足之处,欢迎指正. 第一章 数据库企业应用场景 1.1 数据库的企业应用 MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性.MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言.MySQL软件采用了双授权政策,它分为社区版和商业版,由于其体积小.速度快.总

mariadb主从部署

MariaDB主从服务器优点简介 辅组实现备份Replication 高可用:在主服务器出现异常情况,修改指定配置可以直接顶替主服务器. 异地容灾 Scale out:分摊负载(是否启用!) 一.部署文档 1.确保在主服务器和从服务器上安装的MariaDB版本一致. 2.在主服务器上为从服务器设置一个连接账户 MariaDB [(none)]> GRANT REPLICATION SLAVE, SUPER, RELOAD ON *.* TO ''@'' IDENTIFIED BY '. 主服务器

17.1 MySQL主从介绍17.2 准备工作17.3 配置主17.4 配置从17.5 测试主从同步

- 17.1 MySQL主从介绍 - 17.2 准备工作 - 17.3 配置主 - 17.4 配置从 - 17.5 测试主从同步 # 17.1 MySQL主从介绍 -  MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的 -  MySQL主从是基于binlog的,主上须开启binlog才能进行主从.bilog,是二进制文件,无法cat -  主从过程大致有3个步骤 1. 主将更改操作记录到binlog