Tutorial - Replicação SLAVE (XAMPP v3.2.4) e MASTER - Mysql 8.0

02/09/2022

0

Esse tutorial tem objetivo de complementar outros tutoriais e principalmente, simplificar e eliminar as dificuldades, falhas e erros advindos do procedimento incompleto ou inadequado, presente nos resultados de busca do google.
Portanto, procedimento que se apresenta, resume com a menor quantidade de passos necessários e principalmente, redução de erros e falhas.

CONDIÇÕES INICIAIS:
Servidor SLAVE: Maquina Windows 10, com XAMPP v3.2.4 com MYSQL na porta 3344 e IP 192.168.56.1 - Maquina de desenvolvimento
Servidor MASTER: Maquina Linux Centos, com MySQL 8.0.26 na porta 3307 acessado via SSH IP 192.168.0.50 - Maquina hospedeira
<img src="https://i.postimg.cc/vTyrKg0T/Versao-slave.png">
Banco de dados a replicar: bdtags

================================================Configuração do SLAVE======================================================================
<img src="https://i.postimg.cc/vTyrKg0T/Versao-slave.png">

Arquivo de configuração do MYSQL my.ini, modificar conforme suas TABELAS, porta de comunicação e prestar atenção que é somente uma parte inicial do arquivo padrão
--------------------------------------------------------------------------------------------------------- ARQUIVO MY.INI ---------------------------------------------------------------------------------------------------------------------
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# You can copy this file to
# C:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is C:/xampp/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
# password = your_password
port=3344
socket="C:/xampp/mysql/mysql.sock"
#default-character-set=utf8 #DIA 30/08 PARA CORRIGIR ERRO 22

# Here follows entries for some specific programs

# The MySQL server
default-character-set=utf8mb4
[mysqld]
innodb_file_per_table = on
innodb-flush-method = O_DIRECT

### DUAS LINHAS ABAIXO HABILITAR APOS ESTAR RODANDO EM HOSPEDAGEM
#skip-grant-tables
#skip-slave-start
#innodb_force_recovery = 3 #Se corromper as tabelas habilitar para reparar
### LINHAS ABAIXO FORAM SUBSTITUIDAS POR COMANDOS DO MYSQL NO SLAVE
#master-host = 192.168.0.50
#master-user = replicador
#master-password = replica123
#master-port = 3307
#read_only = true

log-bin=mysql-bin
server-id = 2
relay-log = mysql-relay-bin
log-slave-updates = 1
log_error=mysql-bin.err
binlog_do_db = bdtags #seleciona o banco de dados a replicar
###replicate-ignore-db = bdtags
###replicate-ignore-table = phpmyadmin.%
replicate-ignore-db = phpmyadmin
replicate-ignore-db = bk
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = bdtagZERADO
replicate-ignore-db = mysqlBUG
replicate-ignore-db = raiz_reset
replicate-ignore-db = test

###### nao replicar como MASTER
binlog-ignore-db = bdtags ###IMPEDE A REPLICACAO COMO MASTER
###binlog-ignore-db = phpmyadmin
###binlog-ignore-db = bk
###binlog-ignore-db = mysql
###binlog-ignore-db = information_schema
###binlog-ignore-db = performance_schema

port=3344
socket="C:/xampp/mysql/mysql.sock"
basedir="C:/xampp/mysql"
tmpdir="C:/xampp/tmp"
datadir="C:/xampp/mysql/data"
pid_file="mysql.pid"
# enable-named-pipe
key_buffer=16M
max_allowed_packet=1M
sort_buffer_size=512K
net_buffer_length=8K
read_buffer_size=256K
read_rnd_buffer_size=512K
myisam_sort_buffer_size=8M
log_error="mysql_error.log"

# Change here for bind listening
# bind-address="127.0.0.1"
# bind-address = ::1 # for ipv6

-------------------------------------------------- ARQUIVO MY.INI CONTINUA COM O CONTEUDO PADRAO ------------------------------------------------------------------------------------------------------------------

Abrir o SHELL do PHPMYADMIN inserir o comando: mysql -c mysql -u root -p
<img src="https://i.postimg.cc/NMW5LW3H/check-mysql-erros.png">
Veja que ocorre erros na TABELA MYSQL.
Excluir as tabelas com comandos SQL:
use mysql;
DROP TABLE `gtid_slave_pos`;
DROP TABLE `innodb_index_stats`;
DROP TABLE `innodb_table_stats`;
DROP TABLE `transaction_registry`;

EM SEGUIDA CRIAR AS TABELAS;

CREATE TABLE `gtid_slave_pos` (
`domain_id` int(10) unsigned NOT NULL,
`sub_id` bigint(20) unsigned NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`seq_no` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`domain_id`,`sub_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Replication slave GTID state';

CREATE TABLE `innodb_index_stats` (
`database_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`index_name` varchar(64) COLLATE utf8_bin NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`stat_name` varchar(64) COLLATE utf8_bin NOT NULL,
`stat_value` bigint(20) unsigned NOT NULL,
`sample_size` bigint(20) unsigned DEFAULT NULL,
`stat_description` varchar(1024) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`database_name`,`table_name`,`index_name`,`stat_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `innodb_table_stats` (
`database_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`n_rows` bigint(20) unsigned NOT NULL,
`clustered_index_size` bigint(20) unsigned NOT NULL,
`sum_of_other_index_sizes` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`database_name`,`table_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `transaction_registry` (
`transaction_id` bigint(20) unsigned NOT NULL,
`commit_id` bigint(20) unsigned NOT NULL,
`begin_timestamp` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`commit_timestamp` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000',
`isolation_level` enum('READ-UNCOMMITTED','READ-COMMITTED','REPEATABLE-READ','SERIALIZABLE') COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`transaction_id`),
UNIQUE KEY `commit_id` (`commit_id`),
KEY `begin_timestamp` (`begin_timestamp`),
KEY `commit_timestamp` (`commit_timestamp`,`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;

Posteriormente repetir o comando mysqlcheck -c mysql -u root -p e verificar que todas tabela terão OK

Continuando a configuração do SLAVE. Insira os comandos abaixo de criação do usuario e sua permissão:
CREATE USER 'replicador'@'192.168.0.50' IDENTIFIED BY 'replica123';
GRANT REPLICATION SLAVE ON *.* TO 'replicador'@'192.168.0.50';
SELECT user, authentication_string, plugin, host FROM mysql.user;

Veja que usuario será criado com seu vinculo ao MASTER. Esse usuario que acessará o MASTER.
AGORA iremos vincular a replicacao ao MASTER, os comandos abaixo devem ser MODIFICADOS conforme informação obtida no MASTER através do COMANDO
SHOW MASTER STATUS\G;
Inserir no SLAVE os comandos abaixo;

CHANGE MASTER TO
MASTER_HOST='192.168.0.50',
MASTER_USER='replicador',
MASTER_PASSWORD='replica123',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_PORT=3307,
MASTER_LOG_POS=156;

------------------------------------------------------------------------------------------------------- FIM DA CONFIGURAÇÃO DO SLAVE-----------------------------------------------------------------------------------------------------------
CONTINUA--------------------------------------------------------------------------------------CONFIGURAÇÃO DO MASTER----------------------------------------------------------------------------------
Daniel Fernandes

Daniel Fernandes

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar