Copyright © 2014, Oracle and/or its affiliates. All rights reserved.1
Demo: Replica
Keith Hollman
MySQL Principal Sales Consultant
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3
El entorno de réplica
 1x Master & 1x esclavo
 Mis...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4
Master - esclavo
 Creamos una instancia ‘master’:
c...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5
Master - esclavo
 Usando los valores específicos pa...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6
Master - esclavo
 Instanciando los directorios:
pwd...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7
Master - esclavo
 Creamos algún dato para replicar:...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8
Master - esclavo
 Sacamos una imagen consistente de...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9
Creando el esclavo
 Es hora de crear el esclavo (33...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10
Creando el esclavo
 Creamos la instancia:
scripts/...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11
Creando el esclavo
 Comprobamos la conexión remota...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12
Replicando
show slave status G
 Nada. Bien.
 Le d...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13
Replicando
 Ver los errores, debido a las entradas...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14
Replicando
 Vamos a comprobar si funciona. En el m...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15
Referencias
 MySQL Réplica tutorial:
http://www.my...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16
Questions?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18
Upcoming SlideShare
Loading in …5
×

MySQL Replication: Demo Réplica en Español

701 views

Published on

MySQL Replication technical example in Spanish.
Ejemplo técnico de réplica de MySQL en Español.

Es una guía muy rápida para quitar el miedo a empezar a jugar con réplica.

Published in: Software, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
701
On SlideShare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

MySQL Replication: Demo Réplica en Español

  1. 1. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.1
  2. 2. Demo: Replica Keith Hollman MySQL Principal Sales Consultant
  3. 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3 El entorno de réplica  1x Master & 1x esclavo  Mismo host / servidor  Mismo instalación de software / binarios.  Puertos & rutas diferentes (3306 & 3307)  Réplica asíncrona.
  4. 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4 Master - esclavo  Creamos una instancia ‘master’: cd /usr/local/mysql cp my.cnf my3306.cnf  Añadimos una parametrización más ideal para réplica (my3306.cnf) Preparación server-id =6 log-slave-updates =TRUE gtid-mode =ON enforce-gtid-consistency =TRUE master-info-repository =TABLE relay-log-info-repository =TABLE sync_binlog =1 sync_master_info =1 slave-parallel-workers =2 slave_transaction_retries =0 binlog-checksum =CRC32 master-verify-checksum =1 slave-sql-verify-checksum =1 binlog-rows-query-log-events =1 report-port =3306 log-bin =khollman_3306 binlog_format =ROW report-host =khollman_es
  5. 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5 Master - esclavo  Usando los valores específicos para este entorno, para asegurar que es único y no sobrescribimos nada: port = 3306 datadir = /opt/mysql/3306/data socket = /tmp/mysql_3306.sock server-id = 6 mkdir -p /opt/mysql/3306/data alias mysql3306='/usr/local/mysql/bin/mysql -uroot -poracle -S /tmp/mysql_3306.sock' Preparación II
  6. 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6 Master - esclavo  Instanciando los directorios: pwd = /usr/local/mysql scripts/mysql_install_db --defaults-file=/usr/local/mysql/my3306.cnf --user=mysql --datadir=/opt/mysql/3306/data  Lo arrancamos: bin/mysqld_safe --defaults-file=/usr/local/mysql/my3306.cnf --user=mysql --datadir=/opt/mysql/3306/data &  Ahora, alguna buena práctica de seguridad: ./bin/mysqladmin -u root password 'oracle' -S /tmp/mysql_3306.sock Creando la instancia
  7. 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7 Master - esclavo  Creamos algún dato para replicar: create database nexus; use nexus source /home/mysql/cre_tab_replicant.sql; source /home/mysql/insert_nexus.sql select `First Name`, `Last Name`, `Replicant` from replicant;  Y el usuario que se conectará del esclavo al master para traerse los datos: grant REPLICATION SLAVE on *.* to 'replicant'@'127.0.0.1' identified by 'pkdick' ; Poblamos una base de datos. create table replicant ( `Title` enum('Mr','Mrs','Miss','Ms','M.') not null default 'M.', `First name` varchar(40) not null default '', `Middle name` varchar(40) not null default '', `Last name` varchar(40) not null default '', `Replicant` enum('Yes','No') not null default 'Yes' ) engine=InnoDB; insert into `replicant` (`First name`,`Last name`,`Replicant`) VALUES ('Roy','Hauer','Yes'), ('Rutger','Batty','Yes'), ('Voight','Kampff','Yes'), ('Pris','Hannah','Yes'), ('Daryl','Stratton','Yes'), ('Rachael','Young','Yes'), ('Sean','Tyrell','Yes'), ('Rick','Ford','No'), ('Harrison','Deckard','Yes');
  8. 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8 Master - esclavo  Sacamos una imagen consistente de los datos a replicar: FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS; /usr/local/mysql/bin/mysqldump -uroot -poracle -S /tmp/mysql_3306.sock --set-gtid-purged=OFF --master-data=2 -B nexus > /home/mysql/nexus.sql unlock tables; Exportando los datos
  9. 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9 Creando el esclavo  Es hora de crear el esclavo (3307). alias mysql3307='/usr/local/mysql/bin/mysql -uroot -poracle -S /tmp/mysql_3307.sock‘ prompt slave: R:m d>_ cd /usr/local/mysql cp my3306.cnf my3307.cnf :1,$ s/3306/3307/g  Cambiamos: port, datadir, socket & server-id. mkdir -p /opt/mysql/3307/data Preparación, otra vez.
  10. 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10 Creando el esclavo  Creamos la instancia: scripts/mysql_install_db --defaults-file=/usr/local/mysql/my3307.cnf --user=mysql --datadir=/opt/mysql/3307/data  Arrancamos el esclavo: bin/mysqld_safe --defaults-file=/usr/local/mysql/my3307.cnf --user=mysql --datadir=/opt/mysql/3307/data &  Ahora, alguna buena práctica de seguridad: ./bin/mysqladmin -u root password 'oracle' -S /tmp/mysql_3307.sock Preparación, otra vez II
  11. 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11 Creando el esclavo  Comprobamos la conexión remota, del futuro esclavo al master: bin/mysql -ureplicant -ppkdick -h127.0.0.1 -P3306 -e status  Insertar / cargar los datos previamente exportados: bin/mysql -uroot -poracle -h127.0.0.1 -P3307 < /home/mysql/nexus.sql  Comprobamos: bin/mysql -uroot -poracle -h127.0.0.1 -P3307 nexus select `First Name`, `Last Name`, `Replicant` from replicant; Preparación, otra vez III
  12. 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12 Replicando show slave status G  Nada. Bien.  Le decimos al esclavo cual va a ser su master: change master to master_host='127.0.0.1', master_port=3306, master_user='replicant', master_password='pkdick', master_auto_position=1 ; start slave;  Comprobamos: show slave status G Comenzamos a replicar
  13. 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13 Replicando  Ver los errores, debido a las entradas en el bin-log. El "IO Thread" está ok, pero el "SQL Thread" está parado. drop database nexus; start slave sql_thread; show slave status G  En el esclavo, 3307, creamos el usuario de réplica, por si en el futuro queremos hacer switchover / failover: grant REPLICATION SLAVE on *.* to 'replicant'@'127.0.0.1' identified by 'pkdick' ; Comenzamos a replicar II
  14. 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14 Replicando  Vamos a comprobar si funciona. En el master: bin/mysql -uroot -poracle -h127.0.0.1 -P3306 nexus show slave hosts; insert into replicant (`First Name`,`Last Name`,`Replicant`) values ('Ridley', 'Tyrell','No'), ('Eldon','Scott', 'No'); select `First Name`, `Last Name`, `Replicant` from replicant;  Ver el esclavo: bin/mysql -uroot -poracle -h127.0.0.1 -P3307 nexus show slave status G use nexus; select `First Name`, `Last Name`, `Replicant` from replicant; Comprobamos  prompt master: R:m d>_  prompt slave: R:m d>_
  15. 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15 Referencias  MySQL Réplica tutorial: http://www.mysql.com/why-mysql/white-papers/mysql-replication-tutorial/  Introducción a réplica http://www.mysql.com/why-mysql/white-papers/mysql-replication-introduction/
  16. 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16 Questions?
  17. 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17
  18. 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18

×