首批通过分布式安全可靠测评,为关键业务系统打造
如何限制用户访问的地址段
更新时间:2026-05-09 09:36
本文主要介绍如何限制用户访问的地址段。
OceanBase 数据库中,创建用户的方式兼容 MySQL,如下所示的两种方式都是支持的。
其中 user_name 表示用户名。
CREATE USER 'user_name'@'x.x.x..x' IDENTIFIED BY 'password';
CREATE USER 'user_name'@'x.x.x.%' IDENTIFIED BY 'password';
如果创建了 'user'@'ip_filter',那么在内部的 schema_check 阶段,'user_name'@'x.x.x.x' 会作为一个用户名进行检查。如果使用了其他不允许访问的网段,将提示错误。
例如,为 user_name 设置以下规则,限制其可访问的网段为 192.168.1.%:
obclient> CREATE USER 'user_name'@'192.168.1.%' IDENTIFIED BY 'password';
obclient> GRANT ALL ON test_db.* TO test;
通过其他网段(例如 192.168.2.x)使用 user_name 连接OeanBase 数据库,将提示以下错误,表明配置已生效。
[admin@hostname ~]$ obclient -h<obproxy ip> -P2883 -uuser_name@db_name#cluster_name -p'password'
ERROR 1045 (42000): Access denied for user 'test'@'192.168.2.x' (using password: YES)