MyCat实现——MySQL读写分离

落日映苍穹つ 2023-02-12 11:20 65阅读 0赞

环境配置参考:https://blog.csdn.net/u012948302/article/details/78902092

一、安装jdk

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70

二、github下载解压mycat

2.1、全部下下来,选择自己需要的版本

2.2、拷贝到linux中,解压tar -zxvf jdk-8u151-linux-x64.tar.gz

2.3、测试、启动mycat

  1. [root@localhost bin]# /usr/local/mycat/bin/mycat start

2.4、查看mycat是否启动成功

  1. [root@localhost logs]# cat wrapper.log

三、配置schema.xml、server.xml文件

MyCat配置说明:https://www.cnblogs.com/alan319/p/10556995.html

3.1、schema.xml

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 1

3.2、server.xml

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 2

四、动态切换数据源底层原理实现

五、springboot整合读写分离

1、配置两个数据源已读一写

2、搭建springboot

3、配置yml

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 3

4、配置DataSourceContextHolder

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 4

5、配置DateSourceConfig

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 5

6、将读和写数据源注册到RoutingDataSource

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 6

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 7

6、SwitchDataSourceAOP

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 8

7、主配置类添加扫包

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 9

8、测试

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 10

9、

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2OTQ2ODAz_size_16_color_FFFFFF_t_70 11

发表评论

表情:
评论列表 (有 0 条评论,65人围观)

还没有评论,来说两句吧...

相关阅读