En considérant, que vous avez déjà une architecture fonctionnelle : 1 MASTER MySQL et 1 SLAVE MySQL

Procédures

Procédure : Le SLAVE devient MASTER (on se retrouve avec 2 MASTER)

------------------ PROCEDURE [DEBUT] ------------------ Le SLAVE devient MASTER (on se retrouve avec 2 MASTER)
/**
 * SLAVE : activation des bin log (si elles ne sont pas déjà activées)
 */
 
# Enable binary logging. This is required for acting as a MASTER in a
# replication configuration. You also need the binary log if you need
# the ability to do point in time recovery from your latest backup.
log-bin=mysql-bin
 
# binary logging format - mixed recommended
binlog_format=mixed
 
/**
 * MASTER : verrouiller en écriture
 */
SET GLOBAL read_only = true;
 
# Make the slave read-only. Only users with the SUPER privilege and the
# replication slave thread will be able to modify data on it. You can
# use this to ensure that no applications will accidently modify data on
# the slave instead of the master
read_only
 
/**
 * MASTER : stopper les scheduler
 */
SET GLOBAL event_scheduler = OFF;
 
# Ajout des EVENTS activés au boot
event-scheduler = OFF
 
/**
 * la synchronisation est elle correcte entre les 2 serveur ? 
 *
 
// MASTER : SHOW MASTER STATUS;
File 	mysql-bin.000471
Position 	106
 
// SLAVE : SHOW SLAVE STATUS;
Master_Log_File 	mysql-bin.000471
Read_Master_Log_Pos 	106
Exec_Master_Log_Pos 	106
 
=> OK, on est bien synchronisé, le SLAVE est bien configuré sur le dernier fichier/position des log binaires du master, et à fini d’exécuter toutes les commandes SQL. On peut donc basculer !
 */
 
/**
 * SLAVE : SLAVE => MASTER (ici on déconfigure le SLAVE qui sera autonome/standalone comme un serveur MASTER seul)
 */
STOP SLAVE;
RESET SLAVE; # 5.1
CHANGE MASTER TO MASTER_HOST='', MASTER_PORT=3306, MASTER_USER='', MASTER_PASSWORD='';
RESET MASTER;
SET GLOBAL read_only = false; 
 
# Make the slave read-only. Only users with the SUPER privilege and the
# replication slave thread will be able to modify data on it. You can
# use this to ensure that no applications will accidently modify data on
# the slave instead of the master
#read_only
 
/**
 * SLAVE(new STANDALONE) : activer les scheduler
 */
SET GLOBAL event_scheduler = ON;
 
# Ajout des EVENTS activés au boot
event-scheduler = ON
------------------ PROCEDURE [ FIN ] ------------------ Le SLAVE devient MASTER (on se retrouve avec 2 MASTER)

Procédure : L'ancien MASTER devient SLAVE

------------------ PROCEDURE [DEBUT] ------------------ L'ancien MASTER devient SLAVE
/**
 * FUTURE SLAVE
 */
SET GLOBAL read_only = true;  --  vérouille en écriture
RESET MASTER; -- Efface tous les fichiers de logs binaires dans le fichier d'index, et vide le fichier d'index des logs.
CHANGE MASTER TO MASTER_HOST='mysql51.placeoweb.com', MASTER_PORT=3306, MASTER_USER='replication', MASTER_PASSWORD='password', 
-- MASTER_LOG_FILE = 'master_log_name' # mysql-bin.000001
-- MASTER_LOG_POS = 'master_log_pos' # 332
MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 4
; -- active le slave
START SLAVE;
------------------ PROCEDURE [ FIN ] ------------------ L'ancien MASTER devient SLAVE

Ressources

Les bases de la réplication

-- --------------------
 
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
 
-- --------------------
 
-- REPLICATION CLIENT 	Donne le droit à l'utilisateur de savoir où sont les maîtres et esclaves.
-- REPLICATION SLAVE 	Nécessaire pour les esclaves de réplication (pour lire les historiques binaires du maître).
 
-- MASTER : 
GRANT 
SELECT,
SHOW VIEW,
TRIGGER,
SUPER,
RELOAD,
SHOW DATABASES,
LOCK TABLES,
REPLICATION CLIENT,
REPLICATION SLAVE
ON *.* TO 'replication'@'localhost' IDENTIFIED BY 'password';

Différence MySQL 5.1 et MySQL 5.5

-- On indique au SLAVE 5.1 qu'il n'est plus SLAVE (2 MASTER)
STOP SLAVE;
RESET SLAVE; # 5.1
CHANGE MASTER TO MASTER_HOST='', MASTER_PORT=3306, MASTER_USER='', MASTER_PASSWORD='';
 
-- On indique au SLAVE 5.5 qu'il n'est plus SLAVE (2 MASTER)
STOP SLAVE;
RESET SLAVE ALL; # 5.5

How SHOW SLAVE STATUS relates to CHANGE MASTER TO

Il est très important de comprendre la différence entre la position de l'IO Thread dans les Master logs (Master_Log_File:Read_Master_Log_Pos) et la position du Thread SQL Thread dans les Master logs (Relay_Master_Log_File:Exec_Master_Log_Pos).

Lorsque vous utilisez la commande CHANGE MASTER TO pour définir la position de départ de l'esclave vous spécifiez la position de thread SQL et vous devez donc utiliser Relay_Master_Log_File:Exec_Master_Log_Pos. Sinon, vous allez ruiner votre réplication.

Documentations

FLUSH Syntaxe de FLUSH FLUSH Syntax

FLUSH LOGS : Ferme et réouvre tous les fichiers de log.

FLUSH LOGS, FLUSH MASTER, FLUSH SLAVE, and FLUSH TABLES WITH READ LOCK are not written to the binary log in any case because they would cause problems if replicated to a slave.

PURGE BINARY LOGS PURGE MASTER LOGS PURGE BINARY LOGS Syntax

The PURGE BINARY LOGS statement deletes all the binary log files listed in the log index file prior to the specified log file name or date. BINARY and MASTER are synonyms.

RESET MASTER RESET MASTER RESET MASTER Syntax

Efface tous les fichiers de logs binaires dans le fichier d'index, et vide le fichier d'index des logs.

Important

The effects of RESET MASTER differ from those of PURGE BINARY LOGS in 2 key ways:

  • RESET MASTER removes all binary log files that are listed in the index file, leaving only a single, empty binary log file with a numeric suffix of .000001, whereas the numbering is not reset by PURGE BINARY LOGS.
  • RESET MASTER is not intended to be used while any replication slaves are running. The behavior of RESET MASTER when used while slaves are running is undefined (and thus unsupported), whereas PURGE BINARY LOGS may be safely used while replication slaves are running.
RESET SLAVE RESET SLAVE RESET SLAVE Syntax RESET SLAVE Syntax (5.5)

Force l'esclave a oublier toute les positions de réplications dans les logs du maître. Cette commande permet de faire un démarrage propre : elle efface les fichiers master.info et relay-log.info, et les logs de relais, puis créer un nouveau log de relais.

RESET SLAVE #1198 - This operation cannot be performed with a running slave; run STOP SLAVE first
RESET SLAVE ALL # 5.5
SHOW SLAVE STATUS SHOW SLAVE STATUS SHOW SLAVE STATUS Syntax
Master_Log_File

Le nom du fichier de log binaire que le thread d'I/O utilise sur le maître.

Read_Master_Log_Pos

La position que le thread d'I/O a atteint dans le fichier de log binaire du maître.

Exec_Master_Log_Pos

La position dans les logs binaires du maître (Relay_Master_Log_File) pour le dernier événement exécuté par le thread SQL. ((Relay_Master_Log_File,Exec_Master_Log_Pos) dans le log binaire du maître correspond à (Relay_Log_File,Relay_Log_Pos) dans le log de relais.