4、使用了Mysql读写分离技术
若报错,说明从库目前线程被占用
使用stop slabe停掉
错误解决:
Master Slave 主从同步错误
Slave_IO_Running:NO
Slave_SQL_Running:Yes
#在Slave库上查看状态
mysql> show slave status\G
Slave_IO_Running: No
Slave_SQL_Running: Yes
#重启master库:service mysqld restart
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------------+--------------+--------------+------------------+
| mysql-bin.000534 | 14670663 | | |
+------------------------+--------------+--------------+------------------+
mysql> stop slave;
mysql> change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=98;
mysql> start slave;
mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
使用sharding-JDBC方便实现数据库读写分离
参考配置文件:
rw_dwmo的yml配置文件:
server:
port: 8080
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: ASSIGN_ID
spring:
shardingsphere:
datasource:
names:
master,slave
# 主数据源
master:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.85.128:3306/rw?characterEncoding=utf-8
username: root
password: root
# 从数据源
slave:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.85.12:339rw?characterEncoding=utf-8
username: root
password: root
masterslave:
# 读写分离配置
load-balance-algorithm-type: round_robin #轮询 设置从库数据库负载均衡,例如查询操作时,若有多个从库可轮训发送查找请求,类似nginx
# 最终的数据源名称
name: dataSource
# 主库数据源名称
master-data-source-name: master
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: slave
props:
sql:
show: true #开启SQL显示,默认false main:
allow-bean-definition-overriding: true
瑞吉外卖代码改造: