iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >mysql只读模式下数据迁移,保证数据一致性
  • 247
分享到

mysql只读模式下数据迁移,保证数据一致性

2024-04-02 19:04:59 247人浏览 八月长安
摘要

      在Mysql数据库中,在进行数据迁移和从库只读状态设置时,都会涉及到只读状态和Master-slave的设置和关系。     

   

   在Mysql数据库中,在进行数据迁移和从库只读状态设置时,都会涉及到只读状态和Master-slave的设置和关系。


       经过实际测试,对于mysql单实例数据库和master库,如果需要设置为只读状态,需要进行如下操作和设置:
      

一般单实例情况下将Mysql设置为只读状态的命令:

# mysql -uroot -p
mysql> show global variables like "%read_only%";
mysql>flush tables with read lock;
mysql>set global read_only=1;
mysql> show global variables like "%read_only%";


将MySQL从只读设置为读写状态的命令:

mysql> unlock tables;
mysql>  set global read_only=0;

      对于需要保证master-slave主从同步的salve库,如果要设置为只读状态,需要执行的命令为:
mysql> set global read_only=1;   打开只读开关


     将salve库从只读状态变为读写状态,需要执行的命令是:
mysql> set global read_only=0;   打开读写开关


     对于数据库读写状态,主要靠 “read_only”全局参数来设定;

     默认情况下,数据库是用于读写操作的,所以read_only参数也是0或faluse状态,这时候不论是本地用户还是远程访问数据库的用户,都可以进行读写操作;

      如需设置为只读状态,将该read_only参数设置为1或TRUE状态,但设置 read_only=1 状态有两个需要注意的地方:
      1.read_only=1只读模式,不会影响slave同步复制的功能,所以在MySQL slave库中设定了read_only=1后,通过 show slave status\G 命令查看salve状态,可以看到salve仍然会读取master上的日志,并且在slave库中应用日志,保证主从数据库同步一致;
      2.read_only=1只读模式,可以限定普通用户进行数据修改的操作,但不会限定具有super权限的用户的数据修改操作;在MySQL中设置read_only=1后,普通的应用用户进行insert、update、delete等会产生数据变化的DML操作时,都会报出数据库处于只读模式不能发生数据变化的错误,但具有super权限的用户,例如在本地或远程通过root用户登录到数据库,还是可以进行数据变化的DML操作;


      为了确保所有用户,包括具有super权限的用户也不能进行读写操作,就需要执行给所有的表加读的命令 “flush tables with read lock;”,这样使用具有super权限的用户登录数据库,想要发生数据变化的操作时,也会提示表被锁定不能修改的报错。


        这样通过 设置“read_only=1”和“flush tables with read lock;”两条命令,就可以确保数据库处于只读模式,不会发生任何数据改变,在MySQL进行数据库迁移时,限定master主库不能有任何数据变化,就可以通过这种方式来设定。


       但同时由于加表锁的命令对数据库表限定非常严格,如果再slave从库上执行这个命令后,slave库可以从master读取binlog日志,但不能够应用日志,slave库不能发生数据改变,当然也不能够实现主从同步了,这时如果使用 “unlock tables;”解除全局的表读锁,slave就会应用从master读取到的binlog日志,继续保证主从库数据库一致同步。

       为了保证主从同步可以一直进行,在slave库上要保证具有super权限的root等用户只能在本地登录,不会发生数据变化,其他远程连接的应用用户只按需分配为select,insert,update,delete等权限,保证没有super权限,则只需要将salve设定“read_only=1”模式,即可保证主从同步,又可以实现从库只读。


       相对的,设定“read_only=1”只读模式开启的解锁命令为设定“read_only=0”;设定全局锁“flush tables with read lock;”,对应的解锁模式命令为:“unlock tables;”.
 

      当然设定了read_only=1后,所有的select查询操作都是可以正常进行的。




实验一:设置了read_only=1后,远程业务用户进行数据库修改会提示ERROR 1290错误:


 

 copy
(test01@172.32.1.200) [data03]> show tables;  
+------------------+  
| Tables_in_data03 |  
+------------------+  
| t01              |  
| t02              |  
| user             |  
+------------------+  
3 rows in set (0.00 sec)  
  
(test01@172.32.1.200) [data03]>   
(test01@172.32.1.200) [data03]>   
(test01@172.32.1.200) [data03]> show global variables like "%read_only%";  
+------------------+-------+  
| Variable_name    | Value |  
+------------------+-------+  
| innodb_read_only | OFF   |  
| read_only        | ON    |  
| tx_read_only     | OFF   |  
+------------------+-------+  
3 rows in set (0.00 sec)  
  
(test01@172.32.1.200) [data03]>   
(test01@172.32.1.200) [data03]>   
(test01@172.32.1.200) [data03]> delete from t01 where id1=3;  
<span >ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement</span>  
(test01@172.32.1.200) [data03]> update t01 set id1=id1+30 where id1=3;  
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement  
(test01@172.32.1.200) [data03]> insert into t01(id1,a1,b1) values(9,9,9);  
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement  
(test01@172.32.1.200) [data03]>   
(test01@172.32.1.200) [data03]> select * from t01;  
+-----+------+------+  
| id1 | a1   | b1   |  
+-----+------+------+  
|   1 |    1 |    1 |  
|   2 |    2 |    2 |  
|   4 |    4 |    4 |  
|   5 |    5 |    5 |  
|   6 |    6 |    6 |  
+-----+------+------+  
5 rows in set (0.00 sec)  
  
(test01@172.32.1.200) [data03]>


  •  




实验二:设定了全局读写后,具有super权限的用户进行数据修改后,也会提示错误ERROR 1223:



 

view plain copy
mysql> use data03;  
Reading table infORMation for completion of table and column names  
You can turn off this feature to get a quicker startup with -A  
  
Database changed  
mysql> show tables;  
+------------------+  
| Tables_in_data03 |  
+------------------+  
| t01              |  
| t02              |  
| user             |  
+------------------+  
3 rows in set (0.00 sec)  
  
mysql> select * from t01;  
+-----+------+------+  
| id1 | a1   | b1   |  
+-----+------+------+  
|   1 |    1 |    1 |  
|   2 |    2 |    2 |  
|   4 |    4 |    4 |  
|   5 |    5 |    5 |  
|   6 |    6 |    6 |  
+-----+------+------+  
5 rows in set (0.00 sec)  
  
mysql>   
mysql>  show global variables like "%read_only%";  
+------------------+-------+  
| Variable_name    | Value |  
+------------------+-------+  
| innodb_read_only | OFF   |  
| read_only        | ON    |  
| tx_read_only     | OFF   |  
+------------------+-------+  
3 rows in set (0.00 sec)  
  
mysql>   
mysql>   
mysql> insert into t01(id1,a1,b1) values(8,8,8);         
Query OK, 1 row affected (0.00 sec)  
  
mysql> update t01 set a1=a1+10 where id1=2;  
Query OK, 1 row affected (0.00 sec)  
Rows matched: 1  Changed: 1  Warnings: 0  
  
mysql> delete from t01 where id1=4;  
Query OK, 1 row affected (0.00 sec)  
  
mysql> select * from t01;  
+-----+------+------+  
| id1 | a1   | b1   |  
+-----+------+------+  
|   1 |    1 |    1 |  
|   2 |   12 |    2 |  
|   5 |    5 |    5 |  
|   6 |    6 |    6 |  
|   8 |    8 |    8 |  
+-----+------+------+  
5 rows in set (0.00 sec)  
  
mysql>   
mysql> flush tables with read lock;  
Query OK, 0 rows affected (0.00 sec)  
  
mysql>   
mysql> insert into t01(id1,a1,b1) values(9,9,9);  
<span >ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock</span>  
mysql>   
mysql> update t01 set a1=a1+10 where id1=5;  
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock  
mysql>   
mysql> delete from t01 where id1=5;  
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock  
mysql>   
mysql>


实验三:MySQL从库设定read_only=1后主从同步正常,设定表读锁后,不能同步,解除读锁后,主从同步恢复。



  copy

  1. mysql>   

  2. mysql> show databases;  

  3. +--------------------+  

  4. | Database           |  

  5. +--------------------+  

  6. | information_schema |  

  7. | bitvc              |  

  8. | data03             |  

  9. | ga                 |  

  10. | jiradb             |  

  11. | meibi              |  

  12. | meibi02            |  

  13. | mysql              |  

  14. | performance_schema |  

  15. | sbtest             |  

  16. +--------------------+  

  17. 10 rows in set (0.00 sec)  

  18.   

  19. mysql>   

  20. mysql>   

  21. mysql>   

  22. mysql>  show global variables like "%read_only%";  

  23. +------------------+-------+  

  24. | Variable_name    | Value |  

  25. +------------------+-------+  

  26. | innodb_read_only | OFF   |  

  27. | read_only        | ON    |  

  28. | tx_read_only     | OFF   |  

  29. +------------------+-------+  

  30. 3 rows in set (0.00 sec)  

  31.   

  32. mysql>   

  33. mysql> show slave status\G  

  34. *************************** 1. row ***************************  

  35.                Slave_IO_State: Waiting for master to send event  

  36.                   Master_Host: 172.32.1.200  

  37.                   Master_User: repl  

  38.                   Master_Port: 3307  

  39.                 Connect_Retry: 60  

  40.               Master_Log_File: mysql-bin.000009  

  41.           Read_Master_Log_Pos: 5853  

  42.                Relay_Log_File: huobiDBtest-relay-bin.000002  

  43.                 Relay_Log_Pos: 6016  

  44.         Relay_Master_Log_File: mysql-bin.000009  

  45.              Slave_IO_Running: Yes  

  46.             Slave_SQL_Running: Yes  

  47.               Replicate_Do_DB:   

  48.           Replicate_Ignore_DB:   

  49.            Replicate_Do_Table:   

  50.        Replicate_Ignore_Table:   

  51.       Replicate_Wild_Do_Table:   

    1.   Replicate_Wild_Ignore_Table:   


  52.                    Last_Errno: 0  

  53.                    Last_Error:   

  54.                  Skip_Counter: 0  

  55.           Exec_Master_Log_Pos: 5853  

  56.               Relay_Log_Space: 6195  

  57.               Until_Condition: None  

  58.                Until_Log_File:   

  59.                 Until_Log_Pos: 0  

  60.            Master_SSL_Allowed: No  

  61.            Master_SSL_CA_File:   

  62.            Master_SSL_CA_Path:   

  63.               Master_SSL_Cert:   

  64.             Master_SSL_Cipher:   

  65.                Master_SSL_Key:   

  66.         Seconds_Behind_Master: 0  

  67. Master_SSL_Verify_Server_Cert: No  

  68.                 Last_IO_Errno: 0  

  69.                 Last_IO_Error:   

  70.                Last_SQL_Errno: 0  

  71.                Last_SQL_Error:   

  72.          Replicate_Ignore_Server_Ids:   

  73.            Master_Server_Id: 2003307  

  74.            Master_UUID: 6f68eea7-76e9-11e4-8f99-00221904cd5d  

  75.            Master_Info_File: /data/mysqldata/3308/data/master.info  

  76.            SQL_Delay: 0

  77.            SQL_Remaining_Delay: NULL  

  78.     Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it  

  79.           Master_Retry_Count: 86400  

  80.           Master_Bind:   

  81.           Last_IO_Error_Timestamp:   

  82.           Last_SQL_Error_Timestamp:   

  83.               Master_SSL_Crl:   

  84.            Master_SSL_Crlpath:   

  85.            Retrieved_Gtid_Set:   

  86.             Executed_Gtid_Set:   

  87.                Auto_Position: 0  

  88. 1 row in set (0.00 sec)  

  89.   

  90. mysql>   

  91. mysql> flush tables with read lock;  

  92. Query OK, 0 rows affected (0.00 sec)  

  93.   

  94. mysql> show slave status\G  

  95. *************************** 1. row ***************************  

  96.                Slave_IO_State: Waiting for master to send event  

  97.                   Master_Host: 172.32.1.200  

  98.                   Master_User: repl  

  99.                   Master_Port: 3307  

  100.                 Connect_Retry: 60  

  101.         Master_Log_File: mysql-bin.000009  

  102.           Read_Master_Log_Pos: 6531   

  103.                Relay_Log_File: huobiDBtest-relay-bin.000002  

  104.                 Relay_Log_Pos: 6016  

  105.         Relay_Master_Log_File: mysql-bin.000009  

  106.              Slave_IO_Running: Yes  

  107.             Slave_SQL_Running: Yes  

  108.               Replicate_Do_DB:   

  109.           Replicate_Ignore_DB:   

  110.            Replicate_Do_Table:   

  111.        Replicate_Ignore_Table:   

  112.       Replicate_Wild_Do_Table:   

  113.            Replicate_Wild_Ignore_Table:   

  114.             Last_Errno: 0  

  115.           Last_Error:   


    1.    Skip_Counter: 0  



  116.          Exec_Master_Log_Pos: 5853  

  117.                  Relay_Log_Space: 6873  

  118.               Until_Condition: None  

  119.                Until_Log_File:   

  120.                 Until_Log_Pos: 0  

  121.            Master_SSL_Allowed: No  

  122.            Master_SSL_CA_File:   

  123.            Master_SSL_CA_Path:   

  124.               Master_SSL_Cert:   

  125.             Master_SSL_Cipher:   

  126.                Master_SSL_Key:   

  127.         Seconds_Behind_Master: 120  

  128. Master_SSL_Verify_Server_Cert: No  

  129.                 Last_IO_Errno: 0  

  130.                 Last_IO_Error:   

  131.                Last_SQL_Errno: 0  

  132.                Last_SQL_Error:   

  133.   Replicate_Ignore_Server_Ids:   

  134.              Master_Server_Id: 2003307  

    1.              Master_UUID: 6f68eea7-76e9-11e4-8f99-00221904cd5d  


  135.                   Master_Info_File: /data/mysqldata/3308/data/master.info  

  136.                   SQL_Delay: 0  

  137.           SQL_Remaining_Delay: NULL  

  138.       Slave_SQL_Running_State: Waiting for global read lock  

  139.               Master_Retry_Count: 86400  

  140.               Master_Bind:   

  141.       Last_IO_Error_Timestamp:   

  142.      Last_SQL_Error_Timestamp:   

  143.                Master_SSL_Crl:   

  144.               Master_SSL_Crlpath:   

  145.            Retrieved_Gtid_Set:   

  146.             Executed_Gtid_Set:   

  147.                 Auto_Position: 0  

  148. 1 row in set (0.00 sec)  

  149.   

  150. mysql>   

  151. mysql>   

  152. mysql> select * from data03.t01;  

  153. +-----+------+------+  

  154. | id1 | a1   | b1   |  

  155. +-----+------+------+  

  156. |   1 |    1 |    1 |  

  157. |   2 |    2 |    2 |  

  158. |   4 |    4 |    4 |  

  159. |   5 |    5 |    5 |  

  160. |   6 |    6 |    6 |  

  161. +-----+------+------+  

  162. 5 rows in set (0.00 sec)  

  163.   

  164. mysql>   

  165. mysql> unlock tables;  

  166. Query OK, 0 rows affected (0.00 sec)  

  167.   

  168. mysql> show slave status\G  

  169. *************************** 1. row ***************************  

  170.                Slave_IO_State: Waiting for master to send event  

  171.                   Master_Host: 172.32.1.200  

  172.                   Master_User: repl  

  173.                   Master_Port: 3307  

  174.                 Connect_Retry: 60  

  175.             Master_Log_File: mysql-bin.000009  

  176.           Read_Master_Log_Pos: 6531  

  177.                Relay_Log_File: huobiDBtest-relay-bin.000002  

  178.                 Relay_Log_Pos: 6694  

  179.         Relay_Master_Log_File: mysql-bin.000009  

  180.              Slave_IO_Running: Yes  

  181.             Slave_SQL_Running: Yes  

  182.               Replicate_Do_DB:   

  183.           Replicate_Ignore_DB:   

  184.            Replicate_Do_Table:   

  185.        Replicate_Ignore_Table:   

  186.       Replicate_Wild_Do_Table:   

  187.   Replicate_Wild_Ignore_Table:   

  188.         Last_Errno: 0  

  189.      

        Last_Error:   
                 Skip_Counter: 0  
      Exec_Master_Log_Pos: 6531   
              Relay_Log_Space: 6873  
              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: 2003307  
           Master_UUID: 6f68eea7-76e9-11e4-8f99-00221904cd5d  
            Master_Info_File: /data/mysqldata/3308/data/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:   
            Executed_Gtid_Set:   
            Auto_Position: 0  
1 row in set (0.00 sec)  
  
mysql> select * from data03.t01;  
+-----+------+------+  
| id1 | a1   | b1   |  
+-----+------+------+  
|   1 |    1 |    1 |  
|   2 |   12 |    2 |  
|   5 |    5 |    5 |  
|   6 |    6 |    6 |  
|   8 |    8 |    8 |  
+-----+------+------+  
5 rows in set (0.00 sec)




##########################################

.FLUSH TABLES WITH READ LOCK

 

这个命令是全局读锁定,执行了命令之后所有库所有表都被锁定只读。一般都是用在数据库联机备份,这个时候数据库的写操作将被阻塞,读操作顺利进行。

 

解锁的语句也是unlock tables。


2.LOCK TABLES tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}

 

这个命令是表级别的锁定,可以定制锁定某一个表。例如: lock  tables test read; 不影响其他表的写操作。

解锁语句也是unlock tables。


重点: 

这两个语句在执行的时候都需要注意个特点,就是 隐式提交的语句。在退出MySQL终端的时候都会隐式的执行unlock tables。也就是如果要让表锁定生效就必须一直保持对话。

 

 

P.S.  MYSQL的read lock和wirte lock


read-lock:  允许其他并发的读请求,但阻塞写请求,即可以同时读,但不允许任何写。也叫共享锁

write-lock: 不允许其他并发的读和写请求,是排他的(exclusive)。也叫独占锁




您可能感兴趣的文档:

--结束END--

本文标题: mysql只读模式下数据迁移,保证数据一致性

本文链接: https://www.lsjlt.com/news/39100.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 数据表迁移数据一致性验证
    在迁移数据库的时候做一些必要的验证还是很有用的,比如说迁移前后的数据条数是否一致,数据是否一致,这个时候怎么办呢,验证条数还好说,要是验证数据是否一致呢,对于重要的数据当然要每条都不会有差错,随机抽样验...
    99+
    2024-04-02
  • MySQL保证数据一致性的方式
    这篇文章主要讲解了“MySQL保证数据一致性的方式”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL保证数据一致性的方式”吧!一、MySQL事务模型A...
    99+
    2024-04-02
  • mysql怎么保证数据一致性
    在MySQL中,可以采取以下几种方式来保证数据的一致性:1. 使用事务:事务可以将一系列操作单独的执行单元,要么全部成功提交,要么全...
    99+
    2023-09-15
    mysql
  • redis和mysql数据一致性怎么保证
    为了确保 redis 和 mysql 之间的数据一致性,可以采用以下策略:1. 主从复制:利用 mysql 的复制功能,将 mysql 作为主数据库,并将数据同步到 redis 作为从数...
    99+
    2024-04-08
    mysql redis
  • MySQL和Redis如何保证数据一致性
    MySQL与Redis都是常用的数据存储和缓存系统。为了提高应用程序的性能和可伸缩性,很多应用程序将MySQL和Redis一起使用,其中MySQL作为主要的持久存储,而Redis作为主要的缓存。在这种情况下,应用程序需要确保MySQL和Re...
    99+
    2023-08-22
    mysql redis 数据库
  • Cassandra如何保证数据一致性
    Cassandra 使用了一系列机制来保证数据一致性,包括: 同步复制:Cassandra 采用多节点复制策略,将数据同时复制到...
    99+
    2024-04-09
    Cassandra
  • canal怎么保证数据一致性
    canal可以通过以下方式来保证数据一致性: 基于事务日志解析:canal通过解析数据库的事务日志来获取数据变更的信息。由于数据...
    99+
    2023-10-22
    canal
  • redis如何保证数据一致性
    Redis 保证数据一致性的方法主要有以下几种: 主从复制:Redis 支持主从复制机制,通过将主节点的数据复制到备用的从节点上...
    99+
    2024-05-10
    redis
  • MySQL怎么保证备份数据的一致性
    这篇文章主要讲解了“MySQL怎么保证备份数据的一致性”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL怎么保证备份数据的一致性”吧!前言为了数据安全,数据库需要定期备份,这个大家都懂...
    99+
    2023-06-30
  • redis怎么保证和数据库数据一致性
    Redis是一个内存数据库,通常用作缓存。相比于传统的磁盘数据库,Redis在性能上具有优势,但它也有可能在某些情况下出现数据不一致...
    99+
    2024-02-29
    redis 数据库
  • Cassandra的数据一致性怎么保证
    Cassandra使用了一种称为“最终一致性”的数据一致性模型来保证数据一致性。在这种模型下,不同节点之间的数据可能会出现短暂的不一...
    99+
    2024-05-11
    Cassandra
  • Cassandra如何保证数据的一致性
    Cassandra 通过以下几种方法来保证数据的一致性: Quorum Consistency Level:Cassandra ...
    99+
    2024-04-09
    Cassandra
  • rabbitmq如何保证数据的一致性
    RabbitMQ 通过以下方式来保证数据的一致性: 事务: RabbitMQ 支持事务机制,可以将多条消息发送到队列中原子操作。...
    99+
    2023-10-26
    rabbitmq
  • MySQL与Redis如何保证数据一致性详解
    前言 由于缓存的高并发和高性能已经在各种项目中被广泛使用,在读取缓存这方面基本都是一致的,大概都是按照下图的流程进行操作: 但是在更新缓存方面,是更新完数据库再更新缓存还是直接删...
    99+
    2024-04-02
  • mysql与redis如何保证数据一致
    MySQL和Redis是两种不同类型的数据库,它们在数据存储和数据处理方面有一些不同之处。在将它们结合使用时,需要考虑如何保证数据一...
    99+
    2024-04-18
    mysql redis
  • 如何在Python中进行数据可靠性存储和迁移,以及数据一致性的保证和校验
    如何在Python中进行数据可靠性存储和迁移,以及数据一致性的保证和校验引言:数据的安全性和一致性对于任何应用程序都至关重要。在Python中,我们可以使用一些技术和库来确保数据的可靠性存储和迁移,以及数据一致性的保证和校验。本文将介绍几种...
    99+
    2023-10-22
    数据迁移 数据一致性 数据可靠性存储
  • 怎么保证缓存和数据库的数据一致性
    本篇内容主要讲解“怎么保证缓存和数据库的数据一致性”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么保证缓存和数据库的数据一致性”吧!1、错误的解决方案1.1、...
    99+
    2023-04-21
    数据库
  • 高并发怎么保证数据一致性
    使用redis本身的原子性操作库储存。// redis会返回操作之后的结果,这个过程是原子性的Long currStock = redisTemplate.opsForHash().increment...
    99+
    2024-04-02
  • 保证缓存和数据库的数据一致性详解
    目录1、错误的解决方案1.1、 先更新数据库,再删除缓存1.2、 先更新数据库,再更新缓存1.3、 先删除缓存,再更新数据库1.4、 先更新缓存,再更新数据库2、正确的解决方案2.1...
    99+
    2023-05-15
    缓存和数据库数据一致性 保证缓存和数据库数据一致性 数据一致性
  • redis和数据库如何保证一致性
    redis 与数据库之间的数据一致性可以通过以下机制实现:1. 主从复制机制,通过异步复制实现一致性;2. 双写机制,同时向 redis 和数据库写入数据保持同步;3. 乐观锁,通过版本...
    99+
    2024-04-20
    redis 并发访问
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作