`

How to Set Up Replication

 
阅读更多

.1 Setting the Replication Master Configuration

/etc/my.cnf

[mysqld]
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
#socket = /var/lib/mysql/mysql.sock
user=mysql
bind_address = ::

#bin log conf
log_bin = mysql-bin
binlog_checksum = NONE
binlog_format = ROW
server-id = 2
innodb_flush_log_at_trx_commit=1
sync_binlog=1

 

2 Setting the Replication Slave Configuration

/etc/my.cnf

basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
server_id = 3
# socket = .....
user=mysql
relay-log=mysqld-relay-bin
report-host=hostname
 

3 Creating a User for Replication In master

mysql> CREATE USER 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com';

 

4 Obtaining the Replication Master Binary Log Coordinates

To obtain the master binary log coordinates, follow these steps:

  1. Start a session on the master by connecting to it with the command-line client, and flush all tables and block write statements by executing the FLUSH TABLES WITH READ LOCK statement:

    mysql> FLUSH TABLES WITH READ LOCK;
    

    For InnoDB tables, note that FLUSH TABLES WITH READ LOCK also blocks COMMIT operations.

    Warning

    Leave the client from which you issued the FLUSH TABLES statement running so that the read lock remains in effect. If you exit the client, the lock is released.

  2. In a different session on the master, use the SHOW MASTER STATUS statement to determine the current binary log file name and position:

    mysql > SHOW MASTER STATUS;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000003 | 73       | test         | manual,mysql     |
    +------------------+----------+--------------+------------------+
    

    The File column shows the name of the log file and Position shows the position within the file. In this example, the binary log file is mysql-bin.000003 and the position is 73. Record these values. You need them later when you are setting up the slave. They represent the replication coordinates at which the slave should begin processing new updates from the master.

    If the master has been running previously without binary logging enabled, the log file name and position values displayed by SHOW MASTER STATUS or mysqldump --master-data will be empty. In that case, the values that you need to use later when specifying the slave's log file and position are the empty string ('') and 4.

5 Creating a Data Snapshot Using mysqldump

shell> mysqldump --all-databases --master-data > dbdump.db

 

 

6 Setting Up Replication with Existing Data

 

  1. Start the slave, using the --skip-slave-start option so that replication does not start.

  2. Import the dump file:

    shell> mysql < fulldb.dump
    
c. 
mysql> CHANGE MASTER TO
    ->     MASTER_HOST='master_host_name',
    ->     MASTER_USER='replication_user_name',
    ->     MASTER_PASSWORD='replication_password',
    ->     MASTER_LOG_FILE='recorded_log_file_name',
    ->     MASTER_LOG_POS=recorded_log_position;

 

d. Start the slave threads:

mysql> START SLAVE;

 

 

 

 

 

http://dev.mysql.com/doc/refman/5.6/en/replication-howto.html

分享到:
评论

相关推荐

    PostgreSQL for Data Architects(PACKT,2015)

    After this, you'll learn how to set up replication, use load balancing to scale horizontally, and troubleshoot errors. Finally, you will get acquainted with useful tools available in the PostgreSQL ...

    PostgreSQL for Data Architects 原版PDF by Maymala

    this, you'll learn how to set up replication, use load balancing to scale horizontally, and troubleshoot errors. As you continue through this book, you will see the significant impact of configuration...

    PostgreSQL.for.Data.Architects.1783288604

    After this, you'll learn how to set up replication, use load balancing to scale horizontally, and troubleshoot errors. Finally, you will get acquainted with useful tools available in the PostgreSQL ...

    OpenStack Trove(Apress,2015)

    The book shows you how to set up and configure the Trove DBaaS framework, use prepackaged or custom database implementations, and provision and operate a variety of databases - including MySQL, ...

    OpenStack.Trove.1484212223

    The book shows you how to set up and configure the Trove DBaaS framework, use prepackaged or custom database implementations, and provision and operate a variety of databases—including MySQL, ...

    mysql-8-cookbook2018

    Chapter 9, Replication, explains how to set up various replication topologies. The recipes on switching a slave from master-slave to chain replication and switching a slave from chain replication to ...

    Mastering Apache Cassandra(PACKT,2013)

    Learn how to set up a cluster that can face a tornado of data reads and writes without wincing. If you are a beginner, you can use the examples to help you play around with Cassandra and test the ...

    OpenStack Trove Essentials(PACKT,2016)

    Since Trove is one of the most recent projects of OpenStack, DBAs and system administrators can find it difficult to set up and run a DBaaS using OpenStack Trove. This book helps DBAs make that step. ...

    Redis-Essentials.pdf

    Chapter 7, Security Techniques (Guard Your Data), shows how to set up basic security with Redis, disable and obfuscate commands, protect Redis with firewall rules, and use client-to-server SSL ...

    Packt.Learning.Apache.Kafka.2nd.Edition

    Chapter 2, Setting Up a Kafka Cluster, describes the steps required to set up a single- or multi-broker Kafka cluster and shares the Kafka broker properties list. Chapter 3, Kafka Design, discusses ...

    Real-time Analytics with Storm and Cassandra(PACKT,2015)

    This book will teach you how to use Storm for real-time data processing and to make your applications highly available with no downtime using Cassandra. The book starts off with the basics of Storm ...

    Real-time.Analytics.with.Storm.and.Cassandra.1784395498

    This book will teach you how to use Storm for real-time data processing and to make your applications highly available with no downtime using Cassandra. The book starts off with the basics of Storm ...

    Introducing InnoDB Cluster: Learning the MySQL High Availability Stack

    Set up, manage, and configure the new InnoDB Cluster feature in MySQL from Oracle. If you are growing your MySQL installation and want to explore making your servers highly available, this book ...

    MySQL 8 Cookbook epub 格式

    Perform backup tasks, recover data and set up various replication topologies for your database Maximize performance by using new features of MySQL 8 like descending indexes, controlling query ...

    50 Tips and Tricks for MongoDB Developers

    How do you handle replica set failure and failover? This collection of MongoDB tips, tricks, and hacks helps you resolve issues with everything from application design and implementation to data ...

    Docker - Clustering Payara Server in Docker

    Here’s how to set up a cluster using Docker: ##### Load Balancer A load balancer distributes incoming traffic across nodes in the cluster. For Payara, you can use a software load balancer like ...

Global site tag (gtag.js) - Google Analytics