Mysql-Gtid复制实战&问题总结

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: title: Mysql-Gtid复制实战&问题总结 date: 2019-07-23 10:15:45 categories: Mysql 实践一遍MYSQL的GTID复制,记录总结整个过程,包括: 手动配置GTID主备的方法,重要参数 GTID正常复制场景 GTID异常复制场景 如何修复GTID复制错误 GTID与备份恢复
title: Mysql-Gtid复制实战&问题总结
date: 2019-07-23 10:15:45
categories: Mysql

实践一遍MYSQL的GTID复制,记录总结整个过程,包括:

  • 手动配置GTID主备的方法,重要参数

  • GTID正常复制场景

  • GTID异常复制场景

  • 如何修复GTID复制错误

  • GTID与备份恢复

  • 相关参数

1 Gtid复制配置实战

1.1 环境

使用端口、环境变量隔离两个数据库

部署 IP PORT
主库 127.0.0.1 5404
从库 127.0.0.1 5405

 

1.2 安装MYSQL(省略)

1.3 主备配置

master

[mysqld]
innodb_buffer_pool_size = 128M
basedir = /home/mingjie.gmj/databases/mysql5404
datadir = /home/mingjie.gmj/databases/data/mydata5404
port = 5404
server_id = 06700004
socket = /home/mingjie.gmj/databases/data/mydata5404/mysql5404.sock
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_bin_trust_function_creators = 1
log-bin = /home/mingjie.gmj/databases/data/mydata5404/mysql-bin.log
log-bin-index = /home/mingjie.gmj/databases/data/mydata5404/master-log-bin.index
log-error = /home/mingjie.gmj/databases/data/mydata5404/master-error.log
relay-log = /home/mingjie.gmj/databases/data/mydata5404/slave-relay.log
relay-log-info-file = /home/mingjie.gmj/databases/data/mydata5404/slave-relay-log.info
relay-log-index = /home/mingjie.gmj/databases/data/mydata5404/slave-relay-log.index
master-info-file = /home/mingjie.gmj/databases/data/mydata5404/master.info
log-slave-updates = 1
#read_only = ON
#master_info_repository = TABLE
#relay_log_info_repository = TABLE
binlog_format = ROW
gtid_mode = ON
enforce-gtid-consistency = 1
log-slave-updates = 1
max_binlog_size = 500M
binlog_checksum = CRC32

slave

[mysqld]
innodb_buffer_pool_size = 128M
basedir = /home/mingjie.gmj/databases/mysql5405
datadir = /home/mingjie.gmj/databases/data/mydata5405
port = 5405
server_id = 06700005
socket = /home/mingjie.gmj/databases/data/mydata5405/mysql5405.sock
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_bin_trust_function_creators = 1
log-bin = /home/mingjie.gmj/databases/data/mydata5405/mysql-bin.log
log-bin-index = /home/mingjie.gmj/databases/data/mydata5405/master-log-bin.index
log-error = /home/mingjie.gmj/databases/data/mydata5405/master-error.log
relay-log = /home/mingjie.gmj/databases/data/mydata5405/slave-relay.log
relay-log-info-file = /home/mingjie.gmj/databases/data/mydata5405/slave-relay-log.info
relay-log-index = /home/mingjie.gmj/databases/data/mydata5405/slave-relay-log.index
master-info-file = /home/mingjie.gmj/databases/data/mydata5405/master.info
log-slave-updates = 1
read_only = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
binlog_format = ROW
gtid_mode = ON
enforce-gtid-consistency = 1
log-slave-updates = 1
max_binlog_size = 500M
binlog_checksum = CRC32

1.4 配置主库

配置主库并写入数据

/home/mingjie.gmj/databases/mysql5404/scripts/mysql_install_db --basedir=/home/mingjie.gmj/databases/mysql5404 --datadir=/home/mingjie.gmj/databases/data/mydata5404 --user=mingjie.gmj

/bin/sh /home/mingjie.gmj/databases/mysql5404/bin/mysqld_safe --defaults-file=/home/mingjie.gmj/databases/data/mydata5404/my.cnf &

创建测试表,复制账号

注意:一定把匿名用户删了,要不然连不上!

$ mysql -uroot test

mysql> create table tbl01(id int, info text);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into tbl01 values (1, '001');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tbl01 values (2, '001');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tbl01 values (3, 'info');
Query OK, 1 row affected (0.00 sec)

mysql> grant replication slave, replication client on *.* to repl@'127.0.0.%' identified by '333';
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

导出数据

mysqldump -uroot --all-databases --default-character-set=utf8 -R -q --all-databases --triggers --routines --events --master-data=2 --single-transaction > /tmp/5404.sql

1.5 配置备库

配置备库并写入数据

/home/mingjie.gmj/databases/mysql5405/scripts/mysql_install_db --basedir=/home/mingjie.gmj/databases/mysql5405 --datadir=/home/mingjie.gmj/databases/data/mydata5405 --user=mingjie.gmj

/bin/sh /home/mingjie.gmj/databases/mysql5405/bin/mysqld_safe --defaults-file=/home/mingjie.gmj/databases/data/mydata5405/my.cnf &

创建复制账号

mysql> grant replication slave, replication client on *.* to repl@'127.0.0.%' identified by '333';
Query OK, 0 rows affected (0.00 sec)

重置gtid并导入数据,不重置会报错ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.

mysql> show global variables like '%GTID%';
+---------------------------------+----------------------------------------+
| Variable_name                   | Value                                 |
+---------------------------------+----------------------------------------+
| binlog_gtid_simple_recovery     | OFF                                   |
| enforce_gtid_consistency       | ON                                     |
| gtid_executed                   | 15348f20-ad20-11e9-8bc7-00163f00f11a:1 |
| gtid_mode                       | ON                                     |
| gtid_owned                     |                                       |
| gtid_purged                     |                                       |
| simplified_binlog_gtid_recovery | OFF                                   |
+---------------------------------+----------------------------------------+
7 rows in set (0.00 sec)

mysql> reset master;
Query OK, 0 rows affected (0.01 sec)

mysql> show global variables like '%GTID%';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| binlog_gtid_simple_recovery     | OFF   |
| enforce_gtid_consistency       | ON   |
| gtid_executed                   |       |
| gtid_mode                       | ON   |
| gtid_owned                     |       |
| gtid_purged                     |       |
| simplified_binlog_gtid_recovery | OFF   |
+---------------------------------+-------+
7 rows in set (0.00 sec)


mysql -uroot --default-character-set=utf8 < /tmp/5404.sql

启动复制

位点在导出的dump文件中!

change master to master_host='127.0.0.1',
master_user='repl',
master_password='333',
master_port=5404,
master_log_file='mysql-bin.000001',
master_log_pos=1327;

或者自动找位点

change master to master_host='127.0.0.1',
master_user='repl',
master_password='333',
master_port=5404,
MASTER_AUTO_POSITION=1;

1.6 验证状态

查看备库状态

mysql> show slave status\G
*************************** 1. row ***************************
              Slave_IO_State: Waiting for master to send event
                Master_Host: 127.0.0.1
                Master_User: repl
                Master_Port: 5404
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000001
        Read_Master_Log_Pos: 2175
              Relay_Log_File: slave-relay.000002
              Relay_Log_Pos: 1256
      Relay_Master_Log_File: mysql-bin.000001
            Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            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: 2175
            Relay_Log_Space: 1456
            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: 6700004
                Master_UUID: 673619b8-ad1a-11e9-8ba2-00163f00f11a
            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: 673619b8-ad1a-11e9-8ba2-00163f00f11a:6-8
          Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-8
              Auto_Position: 1
1 row in set (0.00 sec)

正常的复制线程状态

mysql> select * from information_schema.processlist where user<>'root'\G
*************************** 1. row ***************************
    ID: 7
  USER: system user
  HOST:
    DB: NULL
COMMAND: Connect
  TIME: 404
STATE: Waiting for master to send event
  INFO: NULL
*************************** 2. row ***************************
    ID: 8
  USER: system user
  HOST:
    DB: NULL
COMMAND: Connect
  TIME: 273
STATE: Slave has read all relay log; waiting for the slave I/O thread t
  INFO: NULL
2 rows in set (0.01 sec)

 

2 GTID复制测试

2.1 正常复制

继续上面环境主库上执行

mysql> create database tdb;
Query OK, 1 row affected (0.00 sec)

mysql> use tdb;
Database changed

mysql> CREATE TABLE `test1` (`id` int(11) DEFAULT NULL,`count` int(11) DEFAULT NULL);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test1 values(1,1);
Query OK, 1 row affected (0.00 sec)

从库已经执行成功,检查从库的状态

从库Retrieved_Gtid_Set增加了4个事务ID,Executed_Gtid_Set执行了4个事务ID

mysql> show slave status\G
*************************** 1. row ***************************
              Slave_IO_State: Waiting for master to send event
                Master_Host: 127.0.0.1
                Master_User: repl
                Master_Port: 5404
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000001
        Read_Master_Log_Pos: 2753
              Relay_Log_File: slave-relay.000002
              Relay_Log_Pos: 1834
      Relay_Master_Log_File: mysql-bin.000001
            Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            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: 2753
            Relay_Log_Space: 2034
            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: 6700004
                Master_UUID: 673619b8-ad1a-11e9-8ba2-00163f00f11a
            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: 673619b8-ad1a-11e9-8ba2-00163f00f11a:6-11
          Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-11
              Auto_Position: 1

2.2 异常复制场景1——主库日志reset落后于备库

主库执行reset master,插入新数据

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      151 |             |                 |                   |
+------------------+----------+--------------+------------------+-------------------+

mysql> insert into test1 values (8,8);
Query OK, 1 row affected (0.01 sec)

mysql> insert into test1 values (8,9);
Query OK, 1 row affected (0.01 sec)

mysql> insert into test1 values (8,10);
Query OK, 1 row affected (0.00 sec)

mysql> show master status\G
*************************** 1. row ***************************
            File: mysql-bin.000001
        Position: 877
    Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-3
1 row in set (0.00 sec)

备库复制中断

mysql> show slave status\G
*************************** 1. row ***************************
              ...
              ...
              Last_IO_Errno: 1236
              Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Slave has more GTIDs than the master has, using the master's SERVER_UUID. This may indicate that the end of the binary log was truncated or that the last binary log file was lost, e.g., after a power or disk failure when sync_binlog != 1. The master may or may not have rolled back transactions that were already replica'
               ...
               ...
          Retrieved_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:6-11
           Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-11
               Auto_Position: 1
1 row in set (0.00 sec)

备库reset master

ysql> reset master;
Query OK, 0 rows affected (0.01 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |     151 |             |                 |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status\G
*************************** 1. row ***************************
          ...
    Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
          ...
          Retrieved_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-3
          Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-3
              Auto_Position: 1
1 row in set (0.00 sec)

2.3 异常复制场景2——主备不一致备库redo失败

主库表中数据比备库多

mysql> select * from test1;
+------+
| i   |
+------+
|   1 |
|   2 |
|   30 |
|   4 |
|   5 |
|   6 |
|   7 |
|   8 |
|   9 |
+------+
mysql> insert into test1 values (10);
Query OK, 1 row affected (0.00 sec)

mysql> update test1 set i=300 where i=30;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> insert into test1 values (100);
Query OK, 1 row affected (0.00 sec)

备库失败

mysql> select * from test1;
+------+
| i   |
+------+
|   1 |
|   2 |
|   4 |
|   5 |
|   7 |
|   8 |
|   9 |
|   10 |
+------+

mysql> show slave status\G
*************************** 1. row ***************************
              Slave_IO_State: Waiting for master to send event
                Master_Host: 127.0.0.1
                Master_User: repl
                Master_Port: 5404
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000001
        Read_Master_Log_Pos: 1579
              Relay_Log_File: slave-relay.000003
              Relay_Log_Pos: 1309
      Relay_Master_Log_File: mysql-bin.000001
            Slave_IO_Running: Yes
          Slave_SQL_Running: No
            Replicate_Do_DB:
        Replicate_Ignore_DB:
          Replicate_Do_Table:
      Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
                  Last_Errno: 1032
                  Last_Error: Could not execute Update_rows event on table tdb.test1; Can't find record in 'test1', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000001, end_log_pos 1311
                Skip_Counter: 0
        Exec_Master_Log_Pos: 1099
            Relay_Log_Space: 1989
            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: NULL
Master_SSL_Verify_Server_Cert: No
              Last_IO_Errno: 0
              Last_IO_Error:
              Last_SQL_Errno: 1032
              Last_SQL_Error: Could not execute Update_rows event on table tdb.test1; Can't find record in 'test1', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000001, end_log_pos 1311
Replicate_Ignore_Server_Ids:
            Master_Server_Id: 6700004
                Master_UUID: 673619b8-ad1a-11e9-8ba2-00163f00f11a
            Master_Info_File: mysql.slave_master_info
                  SQL_Delay: 0
        SQL_Remaining_Delay: NULL
    Slave_SQL_Running_State:
          Master_Retry_Count: 86400
                Master_Bind:
    Last_IO_Error_Timestamp:
    Last_SQL_Error_Timestamp: 190723 20:13:15
              Master_SSL_Crl:
          Master_SSL_Crlpath:
          Retrieved_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-6
          Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-4
              Auto_Position: 1
1 row in set (0.00 sec)

数据已经不一致了!正常应该备库重新搭,这里做下实验跳过GTID试试。

5号事务是失败的,6号事务是OK的,所以来跳过5号事务!

注意:跳过谁就设谁的位置!

mysql> SET @@SESSION.GTID_NEXT= '673619b8-ad1a-11e9-8ba2-00163f00f11a:5';

mysql> STOP SLAVE;
Query OK, 0 rows affected (0.00 sec)

mysql> SET @@SESSION.GTID_NEXT= '673619b8-ad1a-11e9-8ba2-00163f00f11a:5';
Query OK, 0 rows affected (0.00 sec)

mysql> BEGIN; COMMIT;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> SET SESSION GTID_NEXT = AUTOMATIC;
Query OK, 0 rows affected (0.00 sec)

mysql> START SLAVE;
Query OK, 0 rows affected (0.00 sec)

备库ok

mysql> show slave status\G
*************************** 1. row ***************************
              Slave_IO_State: Waiting for master to send event
                Master_Host: 127.0.0.1
                Master_User: repl
                Master_Port: 5404
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000001
        Read_Master_Log_Pos: 1579
              Relay_Log_File: slave-relay.000004
              Relay_Log_Pos: 685
      Relay_Master_Log_File: mysql-bin.000001
            Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            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: 1579
            Relay_Log_Space: 2523
            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: 6700004
                Master_UUID: 673619b8-ad1a-11e9-8ba2-00163f00f11a
            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: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-6
          Executed_Gtid_Set: 673619b8-ad1a-11e9-8ba2-00163f00f11a:1-6
          &nbs
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
10天前
|
NoSQL 关系型数据库 MySQL
MySQL与Redis协同作战:优化百万数据查询的实战经验
【10月更文挑战第13天】 在处理大规模数据集时,传统的关系型数据库如MySQL可能会遇到性能瓶颈。为了提升数据处理的效率,我们可以结合使用MySQL和Redis,利用两者的优势来优化数据查询。本文将分享一次实战经验,探讨如何通过MySQL与Redis的协同工作来优化百万级数据统计。
30 5
|
20天前
|
架构师 关系型数据库 MySQL
MySQL最左前缀优化原则:深入解析与实战应用
【10月更文挑战第12天】在数据库架构设计与优化中,索引的使用是提升查询性能的关键手段之一。其中,MySQL的最左前缀优化原则(Leftmost Prefix Principle)是复合索引(Composite Index)应用中的核心策略。作为资深架构师,深入理解并掌握这一原则,对于平衡数据库性能与维护成本至关重要。本文将详细解读最左前缀优化原则的功能特点、业务场景、优缺点、底层原理,并通过Java示例展示其实现方式。
43 1
|
5天前
|
监控 关系型数据库 MySQL
数据库优化:MySQL索引策略与查询性能调优实战
【10月更文挑战第27天】本文深入探讨了MySQL的索引策略和查询性能调优技巧。通过介绍B-Tree索引、哈希索引和全文索引等不同类型,以及如何创建和维护索引,结合实战案例分析查询执行计划,帮助读者掌握提升查询性能的方法。定期优化索引和调整查询语句是提高数据库性能的关键。
22 0
|
5天前
|
监控 关系型数据库 MySQL
数据库优化:MySQL索引策略与查询性能调优实战
【10月更文挑战第26天】数据库作为现代应用系统的核心组件,其性能优化至关重要。本文主要探讨MySQL的索引策略与查询性能调优。通过合理创建索引(如B-Tree、复合索引)和优化查询语句(如使用EXPLAIN、优化分页查询),可以显著提升数据库的响应速度和稳定性。实践中还需定期审查慢查询日志,持续优化性能。
27 0
|
2月前
|
监控 关系型数据库 MySQL
zabbix agent集成percona监控MySQL的插件实战案例
这篇文章是关于如何使用Percona监控插件集成Zabbix agent来监控MySQL的实战案例。
47 2
zabbix agent集成percona监控MySQL的插件实战案例
|
3月前
|
SQL 关系型数据库 MySQL
干货!python与MySQL数据库的交互实战
干货!python与MySQL数据库的交互实战
|
3月前
|
存储 关系型数据库 MySQL
实战!MySQL主从复制一键搭建脚本分享
实战!MySQL主从复制一键搭建脚本分享
62 2
|
3月前
|
SQL 存储 关系型数据库
MySQL备份:mydumper 备份恢复工具生产实战
MySQL备份:mydumper 备份恢复工具生产实战
|
3月前
|
关系型数据库 MySQL Linux
【一键解锁神秘力量!】CentOS 7 通过编译源码方式安装 MySQL 数据库 —— 从零到英雄的数据库安装实战秘籍!
【8月更文挑战第9天】随着业务增长,对数据库的需求日益提高。在 CentOS 7 中,通过编译源码安装 MySQL 可提供更高定制性和灵活性。本文详细介绍从准备环境、下载源码、配置编译参数到安装 MySQL 的全过程,并对比 RPM 包安装方法,帮助读者根据需求选择合适方案。实践时需注意备份数据、选择合适版本、确保安全性和调优性能等要点。
205 1
|
3月前
|
存储 关系型数据库 MySQL
MySQL数据库进阶实战:解锁性能飙升秘籍,从菜鸟到高手的华丽蜕变,让数据操作如行云流水!
【8月更文挑战第5天】MySQL是最流行的开源关系型数据库之一,在Web开发与数据分析等领域广泛应用。本文通过实战代码示例,深入探讨MySQL进阶技能:包括索引优化以提升查询性能;利用JOIN与子查询处理多表关联数据;通过事务处理确保数据一致性;使用存储过程与函数封装复杂逻辑以便重用;设置触发器自动执行特定任务以维护数据完整性。掌握这些技能能显著提高数据处理效率与系统性能。
77 5

热门文章

最新文章