MySQL 主从复制是一种常见的数据库架构,它可以提高数据库的性能和可用性。动态数据源切换则可以根据业务需求,在不同场景下使用不同的数据源,比如在读多写少的场景下,可以通过切换到从库来分担主库的压力。 在本文中,我们将介绍如何在 Spring Boot 中实现 MySQL 动态数据源切换,使用 MyBatis-Plus 进行数据库操作 那么接下来我们开始项目实现,项目结构如下 前备:可以提前导入sql create table tb_tutorial ( id bigint auto_increment comment '主键ID' primary key, title varchar(40) null comment '标题', description varchar(30) null comment '描述', published tinyint null comment '1 表示发布 0 表示未发布' ); -- 在从库进行数据添加 INSERT INTO user_db.tb_tutorial (id, title, description, published)...