SlideShare a Scribd company logo
Hệ quản trị cơ sở dữ liệu

Replication
Dư Phương Hạnh
Bộ môn Hệ thống thông tin
Khoa CNTT, trường Đại học Công nghệ
Đại học Quốc gia Hanoi
hanhdp@vnu.edu.vn
Outline





Replication concepts and principles
Setting up replication on master and slave servers
Managing replication
Replication settings

Read more at:
http://mysql-tools.com/en/replication-in-mysql.html

2

Hệ quản trị CSDL @ BM HTTT
Replication concepts and
principles

3

Hệ quản trị CSDL @ BM HTTT
Introduce
 Beside performing regular backups of your
databases, you can also replicate your databases.
 It means you maintain a copy of the database that
is kept up-to-date (synchronized) with the original
database. If the original database becomes
unavailable, the replicated database can continue
to provide users immediate access to the same
data with a minimal amount of downtime.
4

Hệ quản trị CSDL @ BM HTTT
Replicating MySQL Databases
 Updates made to one database copy are
automatically propagated to all the other replicas.
 Generally, one of the replicas is designated as
the master where Updates are directed to the
master while read queries can be addressed to
either the master or the slaves.
 If replicas other than master handle the updates,
then keeping the replicas identical becomes more
complex.
5

Hệ quản trị CSDL @ BM HTTT
Benefits of database replication
 Availability: Any replica can be used as a "hot"
backup.
– If the master database becomes unavailable, this replica
can take over and can be designated as the master. The
failures can be fixed and the failed replica can rejoin as a
slave replica.

 Backups: Replicas can be used as active backups
and can be used to perform tedious offline backups
to file systems without locking up the primary
instance.
6

Hệ quản trị CSDL @ BM HTTT
Benefits of database replication
 Load Balancing: Replicas can serve split loads, also
called load balancing, for heavily used databases.
– Read queries can be distributed to the different replicas
while updates are handled by the master. This scenario
works well when the number of read queries is far greater
than the number of update queries.

 Proximity: Some replicas can be closer to users
leading to improved response time.
 Security: It is harder for malicious users to damage
7

all the replicas.
Hệ quản trị CSDL @ BM HTTT
Availability
One database is
the master while
the other is
designated as a
slave. Only
updates to the
master are
logged.

8

Hệ quản trị CSDL @ BM HTTT
Load Balancing
Read queries are
directed to either
the master or any
of the replicas
while update
queries are
directed only to
the master.

9

Hệ quản trị CSDL @ BM HTTT
MySQL Replication Model
MySQL replication is based on a number of principles:
1.Replication is a one-way, asynchronous process  changes
are always propagated from the master server to the slave
server, but never the other way around.
2.The primary MySQL server acts as the Master server, and
the servers that contain the copied databases are considered
the Slave servers.
3.Data always moves from the master server to the slave
server. As a result, only databases on the master server should
be updated. The updates are then propagated to the slave
servers
10

Hệ quản trị CSDL @ BM HTTT
MySQL Replication Model
4. The master server must be configured with a user account
that grants replication privileges to the slave server. The
account allows the slave server to access the master server
in order to receive updates.
5. Replication is based on the master database server
recording all updates in a binary log  binary logging must
be enabled on the master server. The logged updates are
used to synchronize the database on the slave server.
6. To avoid conflicts, update queries are directed to the master
while read queries can either go to the master or to the
slaves.
11

Hệ quản trị CSDL @ BM HTTT
MySQL Replication Model
7. The replicas connect to the master to read the
binary log and then apply the updates to catch up
with the master.
8. The slave server uses replication coordinates to
track updates.
– The coordinates are based on the name of a binary log
file on the master server and the position in that file. The
file and position represent where MySQL left off when the
last update was performed on the slave server. The
coordinates - along with other logon information - are
12

stored in the master.info file on the slave host.quản trị CSDL @ BM HTTT
Hệ
MySQL Replication Model
9. Each server that participates in the replication process must
be assigned a unique numerical server ID. You assign the
ID by specifying the server-id option in the [mysqld] section
of the option file for each server.
10. A master server can replicate data to one or more slave
servers.
11. To set up replication, the master server and slave server
must begin with databases in a synchronized state. In other
words, the databases to be replicated must be identical
when replication is initiated.
13

Hệ quản trị CSDL @ BM HTTT
MySQL Replication Model
12. No slave server can ever have two master servers.
13. It is generally best to have the master server and
slave servers run the same version of MySQL.
14. There are two core types of replication format
– Statement Based Replication (SBR): replicates entire SQL
statements,
– Row Based Replication (RBR): replicates the changed rows
– You may also use a third variety, Mixed Based Replication
(MBR), which is the default mode within MySQL 5.1.14 and
14

later.
Hệ quản trị CSDL @ BM HTTT
Setting up Replication
 Enable binary logging on the master server.
 Make a backup of the master database.
 Start a new binary log immediately after making the
backup.
 Set up a user account on the master server that
grants replication privileges to the slave server. The
account allows the slave server to access the
master server in order to receive updates.
15

Hệ quản trị CSDL @ BM HTTT
Setting up Replication (2)
 Assign a unique numerical server ID to each server
that participates in the replication process.
 Block all updates to the master.
 Create a Slave instance.
 Load the backup of the master database into the
slave
 Apply the updates from the binary log to the slave to
sync up with the master.
 Get both the master and slave running.
16

Hệ quản trị CSDL @ BM HTTT
Replication Files on the Slave (1)
When replication is implemented, the slave server
maintains a set of files to support the replication.
MySQL automatically creates the three types of files
on the slave server:
1.<host>-relay-bin.<extension>:Contains the
statements to be used to synchronize the replicated
database with the database on the master server, and
then it is deleted.
–
17

The relay log files receive their data from the binary log
files on the master server.
Hệ quản trị CSDL @ BM HTTT
Replication Files on the Slave (2)
2. master.info: Contains connection information such
as the master server hostname, user account and
its password. It also maintains information about
the last binary log file on the master server to be
accessed and the position in that file.
3. relay-log.info: Contains information about the relay
log files and tracks the last position in those files in
which the replicated database was updated.
18

Hệ quản trị CSDL @ BM HTTT
Implementing Replication Details

19

Hệ quản trị CSDL @ BM HTTT
Set up Replication User (on Master)
 To allow a master server to replicate data to a slave
server, you must set up a user account on the
master server.
 The slave server then uses that account to establish
a connection to the master server

20

Hệ quản trị CSDL @ BM HTTT
Set up Replication User (on Master)
GRANT REPLICATION SLAVE ON *.* TO '<slave
account>'@'<slave host>' IDENTIFIED BY '<password>';
The REPLICATION SLAVE privilege at the global level allows
all changes to a database to be replicated to the copy of the
database on the slave server.
TO clause defines the username on the account and host from
which that account can connect. This is the host where the slave
server resides.
The IDENTIFIED BY clause then identifies the password that
should be used when the slave server logs on to the master
server.
21

Hệ quản trị CSDL @ BM HTTT
Making Initial Backup
 Make a backup of the databases that you want to replicate.
Use the --master-data option in the mysqldump command.
The --master-data option adds a CHANGE MASTER
statement similar to the following to your backup file:
CHANGE MASTER TO MASTER_LOG_FILE='mastsrvbin.000201', MASTER_LOG_POS=64;
 CHANGE MASTER statement identifies the binary log file
and the position in that file at the time that the backup file is
created. You use this information later when you set up
replication on the slave server to synchronize the slave
server with the master server.
22

Hệ quản trị CSDL @ BM HTTT
Configuration Changes on Master
(1)
 Shut down the master server.

 Modify the [mysqld] group in the option file on the master
server to specify a server ID for the master server.
– The master server and any slave servers must each be assigned a
unique numerical ID.

 If you don't want to replicate a specific database, such as the
mysql or test databases, you can add a binlog-ignoredb option for each database to prevent changes to that
database from being logged to the binary file.
 Restart the master server.
23

Hệ quản trị CSDL @ BM HTTT
Configuration Changes on Master
(2)
 Two binlog-ignore-db options specify
[mysqld]
log-bin

that changes to the mysql and test

binlog-db=sakila

databases should not be logged to

binlog-ignore-db=mysql

the binary files.

binlog-ignore-db=test
server-id=masterserverID;
log-bin option specifies

 The server-id option specifies the
numbered ID for the master server.
 Note: If you use an existing option

that binary logging should

file, a server-id may already be

be enabled.

present. If multiple options are
specified and the numerical IDs are
different, replication might not work.

24

Hệ quản trị CSDL @ BM HTTT
Configuration Changes on the Slave
 Shut down the slave server.
 Modify the option file on the slave server so that
the [mysqld] section includes the following settings:
server-id=<slave server id>
 Make certain that this server ID is different from the
master server ID and different from any other slave
server IDs. Also be sure that this is the only serverid option defined on the slave server.
 Restart the slave server.
25

Hệ quản trị CSDL @ BM HTTT
Restore Backup on Slave
 Use the backup file created on Master to load the
databases into the slave server

26

Hệ quản trị CSDL @ BM HTTT
Set up Connection to Master
 Specify the settings that
will be used for the slave

 Syntax
CHANGE MASTER TO

server to connect to the

MASTER_HOST='<master host>',

master server and

MASTER_USER='<user account>',

determine which binary log

MASTER_PASSWORD='<passwor

file to access. Launch the
mysql client utility on the
slave server, and execute
CHANGE MASTER
statement.

d>',
MASTER_LOG_FILE='<log file>',
MASTER_LOG_POS=<position>;
 The slave server adds this
information to the master.info file,
which is used when connecting to
the master server.

27

Hệ quản trị CSDL @ BM HTTT
Start Replication on Slave
 The final is to start the replication process on the
slave server. To do so, execute the following SQL
statement on the slave server:
START SLAVE;
 The statement initiates the threads that connect
from the slave server to the master server.

28

Hệ quản trị CSDL @ BM HTTT
Verifying Replication
 Once replication is set up, update a table on the master
server and then confirm whether that change has been
replicated to the slave server.
 To support administering replication, MySQL provides a
number of SQL statements that allow you to view information
about the replication environment or take a specific action.
MySQL supports statements for both the master server and
the slave server.

29

Hệ quản trị CSDL @ BM HTTT
Verifying Replication
 Managing the Master Server:
– RESET MASTER Statement
– SHOW MASTER STATUS Statement
– SHOW SLAVE HOSTS Statement

30

Hệ quản trị CSDL @ BM HTTT
Verifying Replication
 Managing the Slave Server:
– SHOW SLAVE HOSTS Statement
– CHANGE MASTER Statement
– RESET SLAVE Statement
– SHOW SLAVE STATUS Statement
– START SLAVE Statement
– STOP SLAVE Statement

31

Hệ quản trị CSDL @ BM HTTT
Exercise
 Thực hiện đồng bộ hoá CSDL test của bài trước.
– Cấu hình slave server giả lập trên 1 máy tính
– Bật chế độ --log-bin trên master server
– Backup CSDL test trên master server với option –masterdata
– Tạo người dùng cho slave
– Slave server thực hiện restore CSDL test
– Khai báo thông tin để truy cập bin log thực hiện đồng bộ
hoá
– Bắt đầu tiến hành đồng bộ hoá
32

Hệ quản trị CSDL @ BM HTTT

More Related Content

What's hot

database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
sdrhr
 
S3 l7 db2 storage model
S3 l7   db2 storage modelS3 l7   db2 storage model
S3 l7 db2 storage model
Mohammad Khan
 
Database recovery techniques
Database recovery techniquesDatabase recovery techniques
Database recovery techniques
pusp220
 
DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5
Pranav Prakash
 
Memory management in oracle
Memory management in oracleMemory management in oracle
Memory management in oracle
Davin Abraham
 
DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3
Pranav Prakash
 
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
sunildupakuntla
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
Rahul Jamwal
 
Backup and recovery in oracle
Backup and recovery in oracleBackup and recovery in oracle
Backup and recovery in oracle
sadegh salehi
 
Recovery Techniques and Need of Recovery
Recovery Techniques and   Need of RecoveryRecovery Techniques and   Need of Recovery
Recovery Techniques and Need of Recovery
Pooja Dixit
 
Memory management
Memory managementMemory management
Memory management
Muhammad Fayyaz
 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
Mohammad Imam Hossain
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory management
Gokul Vasan
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management
Maitree Patel
 
BACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMSBACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMS
BaivabiNayak
 
Cache memory
Cache memoryCache memory
Cache memory
Eklavya Gupta
 
Process & Mutlithreading
Process & MutlithreadingProcess & Mutlithreading
Process & Mutlithreading
Rahul Jamwal
 
4 (1)
4 (1)4 (1)
4 (1)
Mothi R
 
DB2UDB_the_Basics
DB2UDB_the_BasicsDB2UDB_the_Basics
DB2UDB_the_Basics
Pranav Prakash
 
Topic 4 database recovery
Topic 4 database recoveryTopic 4 database recovery
Topic 4 database recovery
acap paei
 

What's hot (20)

database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
S3 l7 db2 storage model
S3 l7   db2 storage modelS3 l7   db2 storage model
S3 l7 db2 storage model
 
Database recovery techniques
Database recovery techniquesDatabase recovery techniques
Database recovery techniques
 
DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5
 
Memory management in oracle
Memory management in oracleMemory management in oracle
Memory management in oracle
 
DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3
 
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
Backup and recovery in oracle
Backup and recovery in oracleBackup and recovery in oracle
Backup and recovery in oracle
 
Recovery Techniques and Need of Recovery
Recovery Techniques and   Need of RecoveryRecovery Techniques and   Need of Recovery
Recovery Techniques and Need of Recovery
 
Memory management
Memory managementMemory management
Memory management
 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory management
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management
 
BACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMSBACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMS
 
Cache memory
Cache memoryCache memory
Cache memory
 
Process & Mutlithreading
Process & MutlithreadingProcess & Mutlithreading
Process & Mutlithreading
 
4 (1)
4 (1)4 (1)
4 (1)
 
DB2UDB_the_Basics
DB2UDB_the_BasicsDB2UDB_the_Basics
DB2UDB_the_Basics
 
Topic 4 database recovery
Topic 4 database recoveryTopic 4 database recovery
Topic 4 database recovery
 

Viewers also liked

2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sqlTrần Thanh
 
2.1 view
2.1 view2.1 view
2.1 view
Trần Thanh
 
7. backup & restore data
7. backup & restore data7. backup & restore data
7. backup & restore data
Trần Thanh
 
2.3 quan ly truy cap
2.3 quan ly truy cap2.3 quan ly truy cap
2.3 quan ly truy capTrần Thanh
 
ERD - Database Design
ERD - Database DesignERD - Database Design
ERD - Database Design
yht4ever
 
Lập trình sáng tạo creative computing textbook mastercode.vn
Lập trình sáng tạo creative computing textbook mastercode.vnLập trình sáng tạo creative computing textbook mastercode.vn
Lập trình sáng tạo creative computing textbook mastercode.vn
MasterCode.vn
 
6.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part26.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part2
Trần Thanh
 
5. indexing
5. indexing5. indexing
5. indexing
Trần Thanh
 
4.2 transaction
4.2 transaction4.2 transaction
4.2 transaction
Trần Thanh
 
4.2 transaction 2
4.2 transaction 24.2 transaction 2
4.2 transaction 2
Trần Thanh
 
6.1 query optimization overview
6.1 query optimization overview6.1 query optimization overview
6.1 query optimization overviewTrần Thanh
 

Viewers also liked (20)

C3 2
C3 2C3 2
C3 2
 
C2 2
C2 2C2 2
C2 2
 
2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql
 
01 gioithieu
01 gioithieu01 gioithieu
01 gioithieu
 
2.1 view
2.1 view2.1 view
2.1 view
 
9. partitioning
9. partitioning9. partitioning
9. partitioning
 
7. backup & restore data
7. backup & restore data7. backup & restore data
7. backup & restore data
 
C3 2 (tuan6,7)
C3 2 (tuan6,7)C3 2 (tuan6,7)
C3 2 (tuan6,7)
 
Chuan
ChuanChuan
Chuan
 
C4 1 tuan 14
C4 1 tuan 14C4 1 tuan 14
C4 1 tuan 14
 
C3 1
C3 1C3 1
C3 1
 
2.3 quan ly truy cap
2.3 quan ly truy cap2.3 quan ly truy cap
2.3 quan ly truy cap
 
ERD - Database Design
ERD - Database DesignERD - Database Design
ERD - Database Design
 
Lập trình sáng tạo creative computing textbook mastercode.vn
Lập trình sáng tạo creative computing textbook mastercode.vnLập trình sáng tạo creative computing textbook mastercode.vn
Lập trình sáng tạo creative computing textbook mastercode.vn
 
6.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part26.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part2
 
5. indexing
5. indexing5. indexing
5. indexing
 
4.2 transaction
4.2 transaction4.2 transaction
4.2 transaction
 
4.2 transaction 2
4.2 transaction 24.2 transaction 2
4.2 transaction 2
 
6.1 query optimization overview
6.1 query optimization overview6.1 query optimization overview
6.1 query optimization overview
 
07 trigger view
07 trigger view07 trigger view
07 trigger view
 

Similar to 8.replication

Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 En
liufabin 66688
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
PoguttuezhiniVP
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
Dave Stokes
 
MySQL database
MySQL databaseMySQL database
MySQL database
lalit choudhary
 
Download presentation
Download presentationDownload presentation
Download presentation
webhostingguy
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
Vasudeva Rao
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
Dave Stokes
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
Sanmuga Nathan
 
Mysql-Basics.pptx
Mysql-Basics.pptxMysql-Basics.pptx
Mysql-Basics.pptx
ssuserf5adce
 
MySQL HA with PaceMaker
MySQL HA with  PaceMakerMySQL HA with  PaceMaker
MySQL HA with PaceMaker
Kris Buytaert
 
Database Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David IzahkDatabase Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David Izahk
sqlserver.co.il
 
Mysql
MysqlMysql
Mysql
abhijith
 
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaSMariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
Jelastic Multi-Cloud PaaS
 
Google file system
Google file systemGoogle file system
Google file system
Roopesh Jhurani
 
Mysql tutorial
Mysql tutorialMysql tutorial
Mysql tutorial
Pankaj Sipl
 
MySQL HA and Capacity Planning and Architecture
MySQL HA and Capacity Planning and ArchitectureMySQL HA and Capacity Planning and Architecture
MySQL HA and Capacity Planning and Architecture
Abishek V S
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
Jayant Chutke
 
MySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue SolutionsMySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue Solutions
RapidValue
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 

Similar to 8.replication (20)

Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 En
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
MySQL database
MySQL databaseMySQL database
MySQL database
 
Download presentation
Download presentationDownload presentation
Download presentation
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
Mysql-Basics.pptx
Mysql-Basics.pptxMysql-Basics.pptx
Mysql-Basics.pptx
 
MySQL HA with PaceMaker
MySQL HA with  PaceMakerMySQL HA with  PaceMaker
MySQL HA with PaceMaker
 
Database Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David IzahkDatabase Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David Izahk
 
Mysql
MysqlMysql
Mysql
 
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaSMariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
 
Google file system
Google file systemGoogle file system
Google file system
 
Mysql tutorial
Mysql tutorialMysql tutorial
Mysql tutorial
 
MySQL HA and Capacity Planning and Architecture
MySQL HA and Capacity Planning and ArchitectureMySQL HA and Capacity Planning and Architecture
MySQL HA and Capacity Planning and Architecture
 
Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
 
MySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue SolutionsMySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue Solutions
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
 

Recently uploaded

Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 

Recently uploaded (20)

Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 

8.replication

  • 1. Hệ quản trị cơ sở dữ liệu Replication Dư Phương Hạnh Bộ môn Hệ thống thông tin Khoa CNTT, trường Đại học Công nghệ Đại học Quốc gia Hanoi hanhdp@vnu.edu.vn
  • 2. Outline     Replication concepts and principles Setting up replication on master and slave servers Managing replication Replication settings Read more at: http://mysql-tools.com/en/replication-in-mysql.html 2 Hệ quản trị CSDL @ BM HTTT
  • 3. Replication concepts and principles 3 Hệ quản trị CSDL @ BM HTTT
  • 4. Introduce  Beside performing regular backups of your databases, you can also replicate your databases.  It means you maintain a copy of the database that is kept up-to-date (synchronized) with the original database. If the original database becomes unavailable, the replicated database can continue to provide users immediate access to the same data with a minimal amount of downtime. 4 Hệ quản trị CSDL @ BM HTTT
  • 5. Replicating MySQL Databases  Updates made to one database copy are automatically propagated to all the other replicas.  Generally, one of the replicas is designated as the master where Updates are directed to the master while read queries can be addressed to either the master or the slaves.  If replicas other than master handle the updates, then keeping the replicas identical becomes more complex. 5 Hệ quản trị CSDL @ BM HTTT
  • 6. Benefits of database replication  Availability: Any replica can be used as a "hot" backup. – If the master database becomes unavailable, this replica can take over and can be designated as the master. The failures can be fixed and the failed replica can rejoin as a slave replica.  Backups: Replicas can be used as active backups and can be used to perform tedious offline backups to file systems without locking up the primary instance. 6 Hệ quản trị CSDL @ BM HTTT
  • 7. Benefits of database replication  Load Balancing: Replicas can serve split loads, also called load balancing, for heavily used databases. – Read queries can be distributed to the different replicas while updates are handled by the master. This scenario works well when the number of read queries is far greater than the number of update queries.  Proximity: Some replicas can be closer to users leading to improved response time.  Security: It is harder for malicious users to damage 7 all the replicas. Hệ quản trị CSDL @ BM HTTT
  • 8. Availability One database is the master while the other is designated as a slave. Only updates to the master are logged. 8 Hệ quản trị CSDL @ BM HTTT
  • 9. Load Balancing Read queries are directed to either the master or any of the replicas while update queries are directed only to the master. 9 Hệ quản trị CSDL @ BM HTTT
  • 10. MySQL Replication Model MySQL replication is based on a number of principles: 1.Replication is a one-way, asynchronous process  changes are always propagated from the master server to the slave server, but never the other way around. 2.The primary MySQL server acts as the Master server, and the servers that contain the copied databases are considered the Slave servers. 3.Data always moves from the master server to the slave server. As a result, only databases on the master server should be updated. The updates are then propagated to the slave servers 10 Hệ quản trị CSDL @ BM HTTT
  • 11. MySQL Replication Model 4. The master server must be configured with a user account that grants replication privileges to the slave server. The account allows the slave server to access the master server in order to receive updates. 5. Replication is based on the master database server recording all updates in a binary log  binary logging must be enabled on the master server. The logged updates are used to synchronize the database on the slave server. 6. To avoid conflicts, update queries are directed to the master while read queries can either go to the master or to the slaves. 11 Hệ quản trị CSDL @ BM HTTT
  • 12. MySQL Replication Model 7. The replicas connect to the master to read the binary log and then apply the updates to catch up with the master. 8. The slave server uses replication coordinates to track updates. – The coordinates are based on the name of a binary log file on the master server and the position in that file. The file and position represent where MySQL left off when the last update was performed on the slave server. The coordinates - along with other logon information - are 12 stored in the master.info file on the slave host.quản trị CSDL @ BM HTTT Hệ
  • 13. MySQL Replication Model 9. Each server that participates in the replication process must be assigned a unique numerical server ID. You assign the ID by specifying the server-id option in the [mysqld] section of the option file for each server. 10. A master server can replicate data to one or more slave servers. 11. To set up replication, the master server and slave server must begin with databases in a synchronized state. In other words, the databases to be replicated must be identical when replication is initiated. 13 Hệ quản trị CSDL @ BM HTTT
  • 14. MySQL Replication Model 12. No slave server can ever have two master servers. 13. It is generally best to have the master server and slave servers run the same version of MySQL. 14. There are two core types of replication format – Statement Based Replication (SBR): replicates entire SQL statements, – Row Based Replication (RBR): replicates the changed rows – You may also use a third variety, Mixed Based Replication (MBR), which is the default mode within MySQL 5.1.14 and 14 later. Hệ quản trị CSDL @ BM HTTT
  • 15. Setting up Replication  Enable binary logging on the master server.  Make a backup of the master database.  Start a new binary log immediately after making the backup.  Set up a user account on the master server that grants replication privileges to the slave server. The account allows the slave server to access the master server in order to receive updates. 15 Hệ quản trị CSDL @ BM HTTT
  • 16. Setting up Replication (2)  Assign a unique numerical server ID to each server that participates in the replication process.  Block all updates to the master.  Create a Slave instance.  Load the backup of the master database into the slave  Apply the updates from the binary log to the slave to sync up with the master.  Get both the master and slave running. 16 Hệ quản trị CSDL @ BM HTTT
  • 17. Replication Files on the Slave (1) When replication is implemented, the slave server maintains a set of files to support the replication. MySQL automatically creates the three types of files on the slave server: 1.<host>-relay-bin.<extension>:Contains the statements to be used to synchronize the replicated database with the database on the master server, and then it is deleted. – 17 The relay log files receive their data from the binary log files on the master server. Hệ quản trị CSDL @ BM HTTT
  • 18. Replication Files on the Slave (2) 2. master.info: Contains connection information such as the master server hostname, user account and its password. It also maintains information about the last binary log file on the master server to be accessed and the position in that file. 3. relay-log.info: Contains information about the relay log files and tracks the last position in those files in which the replicated database was updated. 18 Hệ quản trị CSDL @ BM HTTT
  • 19. Implementing Replication Details 19 Hệ quản trị CSDL @ BM HTTT
  • 20. Set up Replication User (on Master)  To allow a master server to replicate data to a slave server, you must set up a user account on the master server.  The slave server then uses that account to establish a connection to the master server 20 Hệ quản trị CSDL @ BM HTTT
  • 21. Set up Replication User (on Master) GRANT REPLICATION SLAVE ON *.* TO '<slave account>'@'<slave host>' IDENTIFIED BY '<password>'; The REPLICATION SLAVE privilege at the global level allows all changes to a database to be replicated to the copy of the database on the slave server. TO clause defines the username on the account and host from which that account can connect. This is the host where the slave server resides. The IDENTIFIED BY clause then identifies the password that should be used when the slave server logs on to the master server. 21 Hệ quản trị CSDL @ BM HTTT
  • 22. Making Initial Backup  Make a backup of the databases that you want to replicate. Use the --master-data option in the mysqldump command. The --master-data option adds a CHANGE MASTER statement similar to the following to your backup file: CHANGE MASTER TO MASTER_LOG_FILE='mastsrvbin.000201', MASTER_LOG_POS=64;  CHANGE MASTER statement identifies the binary log file and the position in that file at the time that the backup file is created. You use this information later when you set up replication on the slave server to synchronize the slave server with the master server. 22 Hệ quản trị CSDL @ BM HTTT
  • 23. Configuration Changes on Master (1)  Shut down the master server.  Modify the [mysqld] group in the option file on the master server to specify a server ID for the master server. – The master server and any slave servers must each be assigned a unique numerical ID.  If you don't want to replicate a specific database, such as the mysql or test databases, you can add a binlog-ignoredb option for each database to prevent changes to that database from being logged to the binary file.  Restart the master server. 23 Hệ quản trị CSDL @ BM HTTT
  • 24. Configuration Changes on Master (2)  Two binlog-ignore-db options specify [mysqld] log-bin that changes to the mysql and test binlog-db=sakila databases should not be logged to binlog-ignore-db=mysql the binary files. binlog-ignore-db=test server-id=masterserverID; log-bin option specifies  The server-id option specifies the numbered ID for the master server.  Note: If you use an existing option that binary logging should file, a server-id may already be be enabled. present. If multiple options are specified and the numerical IDs are different, replication might not work. 24 Hệ quản trị CSDL @ BM HTTT
  • 25. Configuration Changes on the Slave  Shut down the slave server.  Modify the option file on the slave server so that the [mysqld] section includes the following settings: server-id=<slave server id>  Make certain that this server ID is different from the master server ID and different from any other slave server IDs. Also be sure that this is the only serverid option defined on the slave server.  Restart the slave server. 25 Hệ quản trị CSDL @ BM HTTT
  • 26. Restore Backup on Slave  Use the backup file created on Master to load the databases into the slave server 26 Hệ quản trị CSDL @ BM HTTT
  • 27. Set up Connection to Master  Specify the settings that will be used for the slave  Syntax CHANGE MASTER TO server to connect to the MASTER_HOST='<master host>', master server and MASTER_USER='<user account>', determine which binary log MASTER_PASSWORD='<passwor file to access. Launch the mysql client utility on the slave server, and execute CHANGE MASTER statement. d>', MASTER_LOG_FILE='<log file>', MASTER_LOG_POS=<position>;  The slave server adds this information to the master.info file, which is used when connecting to the master server. 27 Hệ quản trị CSDL @ BM HTTT
  • 28. Start Replication on Slave  The final is to start the replication process on the slave server. To do so, execute the following SQL statement on the slave server: START SLAVE;  The statement initiates the threads that connect from the slave server to the master server. 28 Hệ quản trị CSDL @ BM HTTT
  • 29. Verifying Replication  Once replication is set up, update a table on the master server and then confirm whether that change has been replicated to the slave server.  To support administering replication, MySQL provides a number of SQL statements that allow you to view information about the replication environment or take a specific action. MySQL supports statements for both the master server and the slave server. 29 Hệ quản trị CSDL @ BM HTTT
  • 30. Verifying Replication  Managing the Master Server: – RESET MASTER Statement – SHOW MASTER STATUS Statement – SHOW SLAVE HOSTS Statement 30 Hệ quản trị CSDL @ BM HTTT
  • 31. Verifying Replication  Managing the Slave Server: – SHOW SLAVE HOSTS Statement – CHANGE MASTER Statement – RESET SLAVE Statement – SHOW SLAVE STATUS Statement – START SLAVE Statement – STOP SLAVE Statement 31 Hệ quản trị CSDL @ BM HTTT
  • 32. Exercise  Thực hiện đồng bộ hoá CSDL test của bài trước. – Cấu hình slave server giả lập trên 1 máy tính – Bật chế độ --log-bin trên master server – Backup CSDL test trên master server với option –masterdata – Tạo người dùng cho slave – Slave server thực hiện restore CSDL test – Khai báo thông tin để truy cập bin log thực hiện đồng bộ hoá – Bắt đầu tiến hành đồng bộ hoá 32 Hệ quản trị CSDL @ BM HTTT

Editor's Notes

  1. CHANGE MASTER TOMASTER_HOST=‘’,MASTER_USER=&apos;&lt;user account&gt;&apos;,MASTER_PASSWORD=&apos;&lt;password&gt;&apos;,MASTER_LOG_FILE=&apos;&lt;log file&gt;&apos;,MASTER_LOG_POS=&lt;position&gt;;