Home Database Mysql Tutorial MySQL5.6基于GTID的主从复制_MySQL

MySQL5.6基于GTID的主从复制_MySQL

May 27, 2016 pm 01:45 PM
gtid master-slave replication

MySQL 5.6 的新特性之一,是加入了全局事务 ID (GTID) 来强化数据库的主备一致性,故障恢复,以及容错能力。

什么是GTID?

官方文档: 代码如下:

mysql> GRANT REPLICATION SLAVE ON *.* TO repluser@172.16.88.205 IDENTIFIED BY 'replpassword';
Copy after login

说明:172.16.88.205是从节点服务器;如果想一次性授权更多的节点,可以自行根据需要修改;

七、启动从数据库上的复制线程

mysql> CHANGE MASTER TO MASTER_HOST='masterdb.example.com', 
MASTER_USER='repluser', MASTER_PASSWORD='replpassword', MASTER_AUTO_POSITION=1;
mysql>start slave;
Copy after login

八、在从数据库上查看复制状态

mysql> show slave status\G;
*************************** 1. row ***************************
    Slave_IO_State: Waiting for master to send event
     Master_Host: masterdb.56xyl.com
     Master_User: repluser
     Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysql-bin.000002
   Read_Master_Log_Pos: 191
    Relay_Log_File: slavedb-relay-bin.000003
    Relay_Log_Pos: 401
  Relay_Master_Log_File: mysql-bin.000002
    Slave_IO_Running: Yes #IO线程已正常运行
   Slave_SQL_Running: Yes #SQL线程已正常运行
    Replicate_Do_DB: 
   Replicate_Ignore_DB: 
   Replicate_Do_Table: 
  Replicate_Ignore_Table: 
  Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
     Last_Errno: 0
     Last_Error: 
     Skip_Counter: 0
   Exec_Master_Log_Pos: 191
    Relay_Log_Space: 1899
    Until_Condition: None
    Until_Log_File: 
    Until_Log_Pos: 0
   Master_SSL_Allowed: No
   Master_SSL_CA_File: 
   Master_SSL_CA_Path: 
    Master_SSL_Cert: 
   Master_SSL_Cipher: 
    Master_SSL_Key: 
  Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
    Last_IO_Errno: 0
    Last_IO_Error: 
    Last_SQL_Errno: 0
    Last_SQL_Error: 
 Replicate_Ignore_Server_Ids: 
    Master_Server_Id: 1
     Master_UUID: 971d7245-c3f8-11e5-8b6b-000c2999e5a5
    Master_Info_File: mysql.slave_master_info
     SQL_Delay: 0
   SQL_Remaining_Delay: NULL
  Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
   Master_Retry_Count: 86400
     Master_Bind: 
  Last_IO_Error_Timestamp: 
  Last_SQL_Error_Timestamp: 
    Master_SSL_Crl: 
   Master_SSL_Crlpath: 
   Retrieved_Gtid_Set: 971d7245-c3f8-11e5-8b6b-000c2999e5a5:1-6
   Executed_Gtid_Set: 89e78301-c3f4-11e5-8b51-00505624d26a:1-3,
971d7245-c3f8-11e5-8b6b-000c2999e5a5:1-6
    Auto_Position: 1
1 row in set (0.00 sec)

ERROR: 
No query specified

mysql>
Copy after login


九、测试

在主库上创建数据库:

mysql> create database log_statics;
Query OK, 1 row affected (0.11 sec)
 
mysql> use log_statics;
Database changed
到从数据库上查看log_statics是否已经复制过去
mysql> show databases;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| log_statics  |
| mysql    |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)

mysql>
Copy after login

可以看到log_statics数据库已经存在于从数据库上。

以上就是MySQL5.6基于GTID的主从复制_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement master-slave replication of MySQL database in PHP How to implement master-slave replication of MySQL database in PHP May 17, 2023 am 08:18 AM

With the rapid development of the Internet, Web applications are increasingly integrating database operations. MySQL is a world-renowned relational database system that is widely used. In highly concurrent web applications, MySQL master-slave replication is an important way to improve database performance and availability. This article will introduce how to use PHP to implement master-slave replication of MySQL database. 1. What is MySQL master-slave replication? MySQL master-slave replication refers to copying data from one MySQL database server to another server.

Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing Sep 09, 2023 am 10:57 AM

Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing In recent years, with the rapid development of the Internet, the database has become one of the core data storage and processing engines for most web applications. In this scenario, high availability and load balancing have become important considerations in database architecture design. As one of the most popular open source relational databases, MySQL's cluster deployment solution has attracted much attention. This article will introduce how to implement a highly available database cluster through MySQL master-slave replication and load balancing.

Data master-slave replication technology in MySQL Data master-slave replication technology in MySQL Jun 14, 2023 pm 02:10 PM

MySQL database is a very popular relational database management system that supports a variety of data replication technologies, among which the more commonly used is master-slave replication technology. This article will introduce the data master-slave replication technology in MySQL, including principles, implementation methods, common problems and countermeasures. 1. Principle of master-slave replication technology The master-slave replication technology in MySQL can copy the data of a MySQL database to other servers to achieve data backup, load balancing, read-write separation and other functions. Its basic principle is to convert the main database

Detailed explanation of the master-slave replication function of Redis Detailed explanation of the master-slave replication function of Redis May 11, 2023 am 10:00 AM

Redis is an open source memory-based key-value storage system that is commonly used in scenarios such as caching, queuing, and real-time data processing. In large-scale applications, in order to improve the availability and performance of Redis, it is often necessary to adopt a distributed architecture, in which master-slave replication is a commonly used mechanism. This article will introduce the master-slave replication function of Redis, including definition, principle, configuration and application scenarios. 1. Definition of Redis master-slave replication refers to automatically synchronizing the data of one Redis node (i.e. master node) to other nodes (i.e. slave node).

How to configure master-slave replication of MySQL database? How to configure master-slave replication of MySQL database? Jul 13, 2023 pm 10:05 PM

How to configure master-slave replication of MySQL database? Master-slave replication of MySQL database is a common data backup and high availability solution. By configuring master-slave replication, you can synchronize data from one MySQL server (master server) to another (slave server), thereby improving database availability and performance. The following describes how to configure master-slave replication in a MySQL database and provides corresponding code examples. Make sure the MySQL server is installed and started. First, make sure MySQL is installed on your system.

Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication Sep 11, 2023 pm 05:51 PM

Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication. With the rapid development of the Internet industry, the demand for data storage and processing is getting higher and higher. In response to high concurrent access and massive data storage, cluster mode has become a common solution. Load balancing and disaster recovery are important components of the cluster system, and MySQL master-slave replication is a widely used method. This article will delve into load balancing and disaster recovery in cluster mode, focusing on the principle of MySQL master-slave replication.

Master-slave replication and high availability architecture in MySQL Master-slave replication and high availability architecture in MySQL Sep 09, 2023 pm 12:03 PM

Master-slave replication and high-availability architecture in MySQL As Internet applications and data volumes continue to grow, the high availability and scalability of the database are becoming more and more important. As a widely used open source relational database, MySQL provides master-slave replication and high-availability architecture solutions. Master-slave replication refers to the process of using a MySQL database instance as the master database and replicating its data to one or more slave databases (slave). This replication method can achieve redundant backup of data and separation of reading and writing.

Achieving data redundancy and expansion: application cases of MySQL master-slave replication technology in cluster environments Achieving data redundancy and expansion: application cases of MySQL master-slave replication technology in cluster environments Sep 08, 2023 pm 04:36 PM

Realizing data redundancy and expansion: Application cases of MySQL master-slave replication technology in cluster environments Introduction: With the development of the Internet, the increasing amount of data and the increasing number of users, traditional stand-alone databases can no longer meet the requirements of high concurrency and high availability. need. In this context, distributed databases have become one of the popular solutions. As one of the most commonly used relational databases, MySQL's master-slave replication technology has also received widespread attention in distributed databases. This article will introduce MySQL master-slave replication technology in a cluster environment

See all articles