AWS RDS跨区域读副本不会复制用户和角色。需要手动将用户和角色授权到读副本上,以便访问该副本。
以下是在AWS RDS中将用户和角色授权给读副本的示例:
CREATE USER 'readonlyuser'@'%' IDENTIFIED BY 'password';
GRANT SELECT ON *.* TO 'readonlyuser'@'%';
CALL mysql.rds_set_configuration('binlog retention hours', 24);
CALL mysql.rds_create_db_parameter_group('custom-param-group', 'mysql5.6');
CALL mysql.rds_modify_db_parameter_group('custom-param-group', 'binlog_format', 'ROW', TRUE);
CALL mysql.rds_create_read_replica('replica-name', 'source-instance', 'custom-param-group', 'readonlyuser', 'password');
mysql -ureadonlyuser -ppassword -h replica-endpoint
SELECT * FROM mytable;
需要注意,以上示例仅展示AWS RDS中为读副本授权的基本流程,实际使用时可能需要根据业务需求进行修改。