MaxScale语句改写
MaxScale的一个很强大功能就是可以对某些SQL进行过滤,比如在生产环境中我可能有这样的需求,不允许执行
某些高危的sql,比如所有delete语句通通禁止.
启用正则表达式模块,改写sql关键字
[fetch]
type=filter
module=regexfilter
match=delete
replace=
[fetch1]
type=filter
module=regexfilter
match=insert
replace=xx
在定义好的路由器上使用这两个filter,多个filter之前用'|'号分开
filters=fetch|qla|fetch1
刚开始的filter不会被激活,只会在第一次使用的时候才会被激活
MaxScale> show filters
Filter 0x109c0a40 (qla)
Module: qlafilter
Options: /tmp/QueryLog
Module not loaded.
Filter 0x109c0860 (fetch)
Module: regexfilter
Module not loaded.
Filter 0x109c0680 (fetch1)
Module: regexfilter
Module not loaded.
在客户端发布以下sql
mysql> delete from sbtest.ttt;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from sbtest.ttt' at line 1
mysql> insert into ttt values(11,12);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx into ttt values(11,12)' at line 1
mysql>
可以看到delete语句失败了,而insert语句的insert关键字好变成了'xx',初步实现了我们的改写sql关键字的目标
现在再次查看两条规则,可以看到已经被激活了
MaxScale> show filters
Filter 0x109c0a40 (qla)
Module: qlafilter
Options: /tmp/QueryLog
Filter 0x109c0860 (fetch)
Module: regexfilter
Search and replace: s/delete//
Filter 0x109c0680 (fetch1)
Module: regexfilter
Search and replace: s/insert/xx/