1. 背景
需要验证:程序查询mylsq失败后执行流程是否符合预期。
待测试的程序:1.定时从mysql中读取数据;2.程序已经配置读写超时。
验证过程:
程序启动之后,添加写锁,下一次查询mysql应该失败,会执行失败流程。发现添加写锁之后,还能正确读取数据。
2. 加锁/解锁
加锁:
- locak table ‘table’ [read|write]
解锁:
- unlock tables
3. 失效原因
加锁之后的表现:
- 程序中定时读取数据正常
- 当前窗口终端,能查询到数据
- 新开启的终端,查询数据阻塞
从表现看 1和2 在加锁前都有从db中读取过数据,3是在加锁之后开始读数据。推测和缓存有关。
查询发现有开启缓存:
MariaDB> show variables like "%query_cache%";
+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 33554432 |
| query_cache_strip_comments | OFF |
| query_cache_type | ON