search
HomeDatabaseMysql Tutorialmysqldump quickly builds a specific library master-slave architecture (GTID)

For a MySQL database with a small amount of data to build a master-slave architecture, it is a good choice to use the mysqldump tool to implement it. Combined with the MySQL GTID feature, it makes high availability a breeze. This article is a supplement to building gtid master-slave based on mysqldump. It mainly introduces the implementation of GTID master-slave based on multi-repository level, that is, not the entire instance level. The following is a detailed description and examples of this article.

Related knowledge point reference
Build gtid master-slave based on mysqldump
MySQL GTID error handling summary
Configure MySQL GTID master-slave replication
Use mysqldump Export database

1. GTID parameters when mysqldump

# mysqldump --help|grep gtid-purged -A8
  --set-gtid-purged[=name] 
                      Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible
                      values for this option are ON, OFF and AUTO. If ON is
                      used and GTIDs are not enabled on the server, an error is
                      generated. If OFF is used, this option does nothing. If
                      AUTO is used and GTIDs are enabled on the server, 'SET
                      @@GLOBAL.GTID_PURGED' is added to the output. If GTIDs
                      are disabled, AUTO does nothing. If no value is supplied                      then the default (AUTO) value will be considered.
        这个参数用于控制在导出数据库时是否导出GTID,针对已开启GTID的mysql实例                      
        就是说导出的数据中已经包含了这些GTID,因此在从库开启从之后需要被跳过
        缺省值为AUTO,如果导出时指定为OFF,则在从库开启从之后会收到error 1236

2. Master-slave environment configuration

        主服务器:192.168.1.233:3306  server_id : 233
        从服务器:192.168.1.245:3306  server_id : 245--在主库端创建复制用户
        (root@Master)[(none)]> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY '123456'; 

-- 查看主库端的配置文件
        (root@Master)[(none)]>system grep -v ^# /etc/my.cnf

        [mysqld]

        sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

        basedir = /usr/local/mysql
        datadir = /data

        server_id=233                
        gtid_mode=on                 
        enforce_gtid_consistency=on  

        log_bin=node233-binlog        log-slave-updates=1    
        binlog_format=row              
        report_host=Master   
        report_port=3306
        master-info-repository = TABLE
        relay-log-info-repository = TABLE
        replicate-do-db=tempdb
        replicate-do-db=testdb

        skip_slave_start=1    ###该参数在启动DB时不会自启动slave,需要手动启动  -- 查看从库端的配置文件 
        (root@Slave)[(none)]>system grep -v ^# /etc/my.cnf

        [mysqld]

        basedir = /usr/local/mysql 
        datadir = /data  

        sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

        server_id=245                
        gtid_mode=on                 
        enforce_gtid_consistency=on  

        log_bin=node245-binlog        log-slave-updates=1    
        binlog_format=row            
        report_host=Slave
        report_port=3306
        master-info-repository = TABLE
        relay-log-info-repository = TABLE
        replicate-do-db=tempdb
        replicate-do-db=testdb

        skip_slave_start=1  ###该参数在启动DB时不会自启动slave,需要手动启动

3. Settings on the main database side

演示环境
        (root@Master)[(none)]>show variables like 'version';
        +---------------+------------+
        | Variable_name | Value      |
        +---------------+------------+
        | version       | 5.7.12-log |
        +---------------+------------+

--创建需要复制的数据库tempdb与testdb        (root@Master)[(none)]>create database tempdb;

        (root@Master)[(none)]>use tempdb;

        (root@Master)[tempdb]>create table tb(`userId` int);

        (root@Master)[(none)]>create database testdb;

        (root@Master)[(none)]>use testdb;

        (root@Master)[testdb]>create table tb(`userId` int);

--主库端执行sql,使用如下脚本        # more insert_id.sh 
        #/bin/sh
        cnt=1

        while [ $cnt -le 10000 ]
        do
                mysql -uroot -ppass -e "insert into tempdb.tb(userId) values($cnt);
                                        insert into testdb.tb(userId) values($cnt)"
                let cnt=$cnt+1
                   sleep 1 
                echo "Insert $cnt"
        done

--执行脚本        # ./insert_id.sh 
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Insert 2
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Insert 3
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Insert 4
             ...........

--dump导出库文件     
        # mysqldump --single-transaction --triggers --routines --events --user=root --password=pass \
        > --databases tempdb testdb  >/tmp/multidb.sql  

--dump文件的内容        # more /tmp/multidb.sql
        -- MySQL dump 10.13  Distrib 5.7.12, for linux-glibc2.5 (x86_64)        --        -- Host: localhost    Database: tempdb        -- ------------------------------------------------------        -- Server version       5.7.12-log        -- 非重要的信息省略 

        SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
        SET @@SESSION.SQL_LOG_BIN= 0;

        --        -- GTID state at the beginning of the backup        --
        --GTID信息,重要,用于主从复制跳过)        SET @@GLOBAL.GTID_PURGED='1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2318';

        --        -- Current Database: `tempdb`        --
        CREATE DATABASE /*!32312 IF NOT EXISTS*/ `tempdb` /*!40100 DEFAULT CHARACTER SET latin1 */;

        USE `tempdb`;

        --        -- Table structure for table `tb`        --
        DROP TABLE IF EXISTS `tb`;        /*!40101 SET @saved_cs_client     = @@character_set_client */;        /*!40101 SET character_set_client = utf8 */;
        CREATE TABLE `tb` (
          `userId` int(11) DEFAULT NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;        /*!40101 SET character_set_client = @saved_cs_client */;

        --        -- Dumping data for table `tb`        --
        LOCK TABLES `tb` WRITE;        /*!40000 ALTER TABLE `tb` DISABLE KEYS */;
        INSERT INTO `tb` VALUES (1),(2),(3),(4),(5);        /*!40000 ALTER TABLE `tb` ENABLE KEYS */;
        UNLOCK TABLES;

        --        -- Dumping events for database 'tempdb'        --
        --        -- Dumping routines for database 'tempdb'        --
        --        -- Current Database: `testdb`        --
        CREATE DATABASE /*!32312 IF NOT EXISTS*/ `testdb` /*!40100 DEFAULT CHARACTER SET latin1 */;

        USE `testdb`;

        --        -- Table structure for table `tb`        --
        DROP TABLE IF EXISTS `tb`;        /*!40101 SET @saved_cs_client     = @@character_set_client */;        /*!40101 SET character_set_client = utf8 */;
        CREATE TABLE `tb` (
          `userId` int(11) DEFAULT NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;        /*!40101 SET character_set_client = @saved_cs_client */;

        --        -- Dumping data for table `tb`        --
        LOCK TABLES `tb` WRITE;        /*!40000 ALTER TABLE `tb` DISABLE KEYS */;
        INSERT INTO `tb` VALUES (1),(2),(3),(4),(5);        /*!40000 ALTER TABLE `tb` ENABLE KEYS */;
        UNLOCK TABLES;

        --        -- Dumping events for database 'testdb'        --
        -- 在上面dump出来的每个表中可以看到导出的时候已经产生了数据1-5        -- Dumping routines for database 'testdb'        --        SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;

--将导出文件复制到从服务器        [root@node233 ~]# scp /tmp/multidb.sql 192.168.1.245:/tmp

4. Slave Library-side settings

(root@Slave)[(none)]>reset master;
        Query OK, 0 rows affected (0.02 sec)

        (root@Slave)[(none)]>reset slave all;
        Query OK, 0 rows affected (0.04 sec)

        (root@Slave)[(none)]>source /tmp/multidb.sql

        (root@Slave)[tempdb]>CHANGE MASTER TO  
            -> MASTER_HOST='192.168.1.233',    
            -> MASTER_USER='repl',    
            -> MASTER_PASSWORD='123456',    
            -> MASTER_PORT=3306,    
            -> MASTER_AUTO_POSITION = 1;
        Query OK, 0 rows affected, 2 warnings (0.07 sec)

        (root@Slave)[tempdb]>start slave;
        Query OK, 0 rows affected (0.05 sec)

        (root@Slave)[testdb]>show slave status\G        *************************** 1. row ***************************
                       Slave_IO_State: Waiting for master to send event
                          Master_Host: Master
                          Master_User: repl
                          Master_Port: 3306
                        Connect_Retry: 60
                      Master_Log_File: node233-binlog.000008
                  Read_Master_Log_Pos: 201141
                       Relay_Log_File: node245-relay-bin.000002
                        Relay_Log_Pos: 96813
                Relay_Master_Log_File: node233-binlog.000008
                     Slave_IO_Running: Yes
                    Slave_SQL_Running: Yes
                      Replicate_Do_DB: tempdb,testdb
                  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: 201141
                      Relay_Log_Space: 97062
                      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: 233
                          Master_UUID: 1b64c25d-8d2b-11e6-9ac0-000c29b82d0d
                     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 more updates
                   Master_Retry_Count: 86400
                          Master_Bind:   -- Author : Leshami
              Last_IO_Error_Timestamp:   -- Blog   : http://blog.csdn.net/leshami
             Last_SQL_Error_Timestamp: 
                       Master_SSL_Crl: 
                   Master_SSL_Crlpath: 
                   Retrieved_Gtid_Set: 1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:2319-2702
                    Executed_Gtid_Set: 1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2702
                        Auto_Position: 1
                 Replicate_Rewrite_DB: 
                         Channel_Name: 
                   Master_TLS_Version:

5. Verify the master-slave record

--以下查询中可以看到,两个数据库的表中的记录在不停的增加
        (root@Slave)[testdb]>select count(*) from tb;
        +----------+
        | count(*) |
        +----------+          
        |      206 |
        +----------+

        (root@Slave)[testdb]>select count(*) from tempdb.tb;
        +----------+
        | count(*) |
        +----------+
        |      214 |
        +----------+

        (root@Slave)[testdb]>select count(*) from tb;
        +----------+
        | count(*) |
        +----------+
        |      216 |
        +----------+

        (root@Slave)[testdb]>select count(*) from tempdb.tb;
        +----------+
        | count(*) |
        +----------+
        |      218 |
        +----------+

mysqldump quickly builds a specific library master-slave architecture (GTID)

##To build a master-slave architecture for a MySQL database with a small amount of data, use The mysqldump tool is a good choice to implement, and combined with the MySQL GTID feature, it makes high availability a breeze. This article is a supplement to building gtid master-slave based on mysqldump. It mainly introduces the implementation of GTID master-slave based on multi-repository level, that is, not the entire instance level. The following is a detailed description and examples of this article.

Related knowledge point reference

Build gtid master-slave based on mysqldump
MySQL GTID error handling summary
Configure MySQL GTID master-slave replication
Use mysqldump to export the database

1. GTID parameters during mysqldump

# mysqldump --help|grep gtid-purged -A8
  --set-gtid-purged[=name] 
                      Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible
                      values for this option are ON, OFF and AUTO. If ON is
                      used and GTIDs are not enabled on the server, an error is
                      generated. If OFF is used, this option does nothing. If
                      AUTO is used and GTIDs are enabled on the server, 'SET
                      @@GLOBAL.GTID_PURGED' is added to the output. If GTIDs
                      are disabled, AUTO does nothing. If no value is supplied                      then the default (AUTO) value will be considered.
        这个参数用于控制在导出数据库时是否导出GTID,针对已开启GTID的mysql实例                      
        就是说导出的数据中已经包含了这些GTID,因此在从库开启从之后需要被跳过
        缺省值为AUTO,如果导出时指定为OFF,则在从库开启从之后会收到error 1236

2. Master-slave environment configuration

        主服务器:192.168.1.233:3306  server_id : 233
        从服务器:192.168.1.245:3306  server_id : 245--在主库端创建复制用户
        (root@Master)[(none)]> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY '123456'; 

-- 查看主库端的配置文件
        (root@Master)[(none)]>system grep -v ^# /etc/my.cnf

        [mysqld]

        sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

        basedir = /usr/local/mysql
        datadir = /data

        server_id=233                
        gtid_mode=on                 
        enforce_gtid_consistency=on  

        log_bin=node233-binlog        log-slave-updates=1    
        binlog_format=row              
        report_host=Master   
        report_port=3306
        master-info-repository = TABLE
        relay-log-info-repository = TABLE
        replicate-do-db=tempdb
        replicate-do-db=testdb

        skip_slave_start=1    ###该参数在启动DB时不会自启动slave,需要手动启动  -- 查看从库端的配置文件 
        (root@Slave)[(none)]>system grep -v ^# /etc/my.cnf

        [mysqld]

        basedir = /usr/local/mysql 
        datadir = /data  

        sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

        server_id=245                
        gtid_mode=on                 
        enforce_gtid_consistency=on  

        log_bin=node245-binlog        log-slave-updates=1    
        binlog_format=row            
        report_host=Slave
        report_port=3306
        master-info-repository = TABLE
        relay-log-info-repository = TABLE
        replicate-do-db=tempdb
        replicate-do-db=testdb

        skip_slave_start=1  ###该参数在启动DB时不会自启动slave,需要手动启动

3. Settings on the main library side

演示环境
        (root@Master)[(none)]>show variables like 'version';
        +---------------+------------+
        | Variable_name | Value      |
        +---------------+------------+
        | version       | 5.7.12-log |
        +---------------+------------+

--创建需要复制的数据库tempdb与testdb        (root@Master)[(none)]>create database tempdb;

        (root@Master)[(none)]>use tempdb;

        (root@Master)[tempdb]>create table tb(`userId` int);

        (root@Master)[(none)]>create database testdb;

        (root@Master)[(none)]>use testdb;

        (root@Master)[testdb]>create table tb(`userId` int);

--主库端执行sql,使用如下脚本        # more insert_id.sh 
        #/bin/sh
        cnt=1

        while [ $cnt -le 10000 ]
        do
                mysql -uroot -ppass -e "insert into tempdb.tb(userId) values($cnt);
                                        insert into testdb.tb(userId) values($cnt)"
                let cnt=$cnt+1
                   sleep 1 
                echo "Insert $cnt"
        done

--执行脚本        # ./insert_id.sh 
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Insert 2
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Insert 3
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Insert 4
             ...........

--dump导出库文件     
        # mysqldump --single-transaction --triggers --routines --events --user=root --password=pass \
        > --databases tempdb testdb  >/tmp/multidb.sql  

--dump文件的内容        # more /tmp/multidb.sql
        -- MySQL dump 10.13  Distrib 5.7.12, for linux-glibc2.5 (x86_64)        --        -- Host: localhost    Database: tempdb        -- ------------------------------------------------------        -- Server version       5.7.12-log        -- 非重要的信息省略 

        SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
        SET @@SESSION.SQL_LOG_BIN= 0;

        --        -- GTID state at the beginning of the backup        --
        --GTID信息,重要,用于主从复制跳过)        SET @@GLOBAL.GTID_PURGED='1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2318';

        --        -- Current Database: `tempdb`        --
        CREATE DATABASE /*!32312 IF NOT EXISTS*/ `tempdb` /*!40100 DEFAULT CHARACTER SET latin1 */;

        USE `tempdb`;

        --        -- Table structure for table `tb`        --
        DROP TABLE IF EXISTS `tb`;        /*!40101 SET @saved_cs_client     = @@character_set_client */;        /*!40101 SET character_set_client = utf8 */;
        CREATE TABLE `tb` (
          `userId` int(11) DEFAULT NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;        /*!40101 SET character_set_client = @saved_cs_client */;

        --        -- Dumping data for table `tb`        --
        LOCK TABLES `tb` WRITE;        /*!40000 ALTER TABLE `tb` DISABLE KEYS */;
        INSERT INTO `tb` VALUES (1),(2),(3),(4),(5);        /*!40000 ALTER TABLE `tb` ENABLE KEYS */;
        UNLOCK TABLES;

        --        -- Dumping events for database 'tempdb'        --
        --        -- Dumping routines for database 'tempdb'        --
        --        -- Current Database: `testdb`        --
        CREATE DATABASE /*!32312 IF NOT EXISTS*/ `testdb` /*!40100 DEFAULT CHARACTER SET latin1 */;

        USE `testdb`;

        --        -- Table structure for table `tb`        --
        DROP TABLE IF EXISTS `tb`;        /*!40101 SET @saved_cs_client     = @@character_set_client */;        /*!40101 SET character_set_client = utf8 */;
        CREATE TABLE `tb` (
          `userId` int(11) DEFAULT NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;        /*!40101 SET character_set_client = @saved_cs_client */;

        --        -- Dumping data for table `tb`        --
        LOCK TABLES `tb` WRITE;        /*!40000 ALTER TABLE `tb` DISABLE KEYS */;
        INSERT INTO `tb` VALUES (1),(2),(3),(4),(5);        /*!40000 ALTER TABLE `tb` ENABLE KEYS */;
        UNLOCK TABLES;

        --        -- Dumping events for database 'testdb'        --
        -- 在上面dump出来的每个表中可以看到导出的时候已经产生了数据1-5        -- Dumping routines for database 'testdb'        --        SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;

--将导出文件复制到从服务器        [root@node233 ~]# scp /tmp/multidb.sql 192.168.1.245:/tmp

4. Settings on the slave library side

(root@Slave)[(none)]>reset master;
        Query OK, 0 rows affected (0.02 sec)

        (root@Slave)[(none)]>reset slave all;
        Query OK, 0 rows affected (0.04 sec)

        (root@Slave)[(none)]>source /tmp/multidb.sql

        (root@Slave)[tempdb]>CHANGE MASTER TO  
            -> MASTER_HOST='192.168.1.233',    
            -> MASTER_USER='repl',    
            -> MASTER_PASSWORD='123456',    
            -> MASTER_PORT=3306,    
            -> MASTER_AUTO_POSITION = 1;
        Query OK, 0 rows affected, 2 warnings (0.07 sec)

        (root@Slave)[tempdb]>start slave;
        Query OK, 0 rows affected (0.05 sec)

        (root@Slave)[testdb]>show slave status\G        *************************** 1. row ***************************
                       Slave_IO_State: Waiting for master to send event
                          Master_Host: Master
                          Master_User: repl
                          Master_Port: 3306
                        Connect_Retry: 60
                      Master_Log_File: node233-binlog.000008
                  Read_Master_Log_Pos: 201141
                       Relay_Log_File: node245-relay-bin.000002
                        Relay_Log_Pos: 96813
                Relay_Master_Log_File: node233-binlog.000008
                     Slave_IO_Running: Yes
                    Slave_SQL_Running: Yes
                      Replicate_Do_DB: tempdb,testdb
                  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: 201141
                      Relay_Log_Space: 97062
                      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: 233
                          Master_UUID: 1b64c25d-8d2b-11e6-9ac0-000c29b82d0d
                     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 more updates
                   Master_Retry_Count: 86400
                          Master_Bind:   -- Author : Leshami
              Last_IO_Error_Timestamp:   -- Blog   : http://blog.csdn.net/leshami
             Last_SQL_Error_Timestamp: 
                       Master_SSL_Crl: 
                   Master_SSL_Crlpath: 
                   Retrieved_Gtid_Set: 1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:2319-2702
                    Executed_Gtid_Set: 1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2702
                        Auto_Position: 1
                 Replicate_Rewrite_DB: 
                         Channel_Name: 
                   Master_TLS_Version:

5. Verify the master-slave record

--以下查询中可以看到,两个数据库的表中的记录在不停的增加
        (root@Slave)[testdb]>select count(*) from tb;
        +----------+
        | count(*) |
        +----------+          
        |      206 |
        +----------+

        (root@Slave)[testdb]>select count(*) from tempdb.tb;
        +----------+
        | count(*) |
        +----------+
        |      214 |
        +----------+

        (root@Slave)[testdb]>select count(*) from tb;
        +----------+
        | count(*) |
        +----------+
        |      216 |
        +----------+

        (root@Slave)[testdb]>select count(*) from tempdb.tb;
        +----------+
        | count(*) |
        +----------+
        |      218 |
        +----------+

mysqldump quickly builds a specific library master-slave architecture (GTID)

The above is the content of mysqldump to quickly build the master-slave architecture (GTID) of a specific library. For more related content, please pay attention to PHP Chinese Net (www.php.cn)!

Statement
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
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft