当前位置:网站首页>MySQL master-slave connection prompt of docker: communications link failure
MySQL master-slave connection prompt of docker: communications link failure
2022-06-22 17:03:00 【On the road of struggle】
In use today Apache ShardingSphere Realize the database read-write separation function , The connection is based on Docker Of MySQL5.7 Master-slave IP.SpringBoot The program prompts the following error message :
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure
Reason for the error :MySQL The service was disconnected after a long period of inactivity , The first request after disconnection will throw this exception
Cause analysis :
1、 Since it was disconnected after a long time of disconnection , The time should be settable , Or now mysql Using the default value
2、 How to view the current time value , And how to modify based on docker Service started MySQL.
View the default values :
1、 Use Native For MySQL Client tools , Execute the following instructions :show variables like '%timeout%'

Parameter description :
1)interactive_timeout:
Parameter meaning : The number of seconds the server waits for activity before shutting down the interactive connection . The interactive client is defined as mysql_real_connect() Use in CLIENT_INTERACTIVE Option client .
Parameter default :28800 second (8 Hours )
2)wait_timeout:
Parameter meaning : The number of seconds the server waits for activity before shutting down non interactive connections . When the thread starts , According to the global wait_timeout Value or global interactive_timeout Value initializes the session wait_timeout value , Depends on the client type (mysql_real_connect() Connection options for CLIENT_INTERACTIVE Definition ).
Parameter default :28800 second (8 Hours )
reminder : stay MySQL4 And below , Can pass autoReconnect=true Configure properties to solve the problem of automatic connection recovery , If it is MySQL5 And above , Must pass System parameters to control .
Conclusion : To modify , You need to modify both variables at the same time
Connection time value range : stay windows Environment :1-2147483s,
stay Linux Environment :1-31536000s
Docker Modify the MySQL:MySQL5.7 stay Docker The core configuration file under , It is realized by hanging the roll , So we just need to modify Docker The address of the mount directory where the host is located , Modify the corresponding file .
docker start-up MySQL5.7:
docker run -p 3307:3306 --name mysql-master \
-v /usr/local/mysql-master/log:/var/log/mysql \
-v /usr/local/mysql-master/data:/var/lib/mysql \
-v /usr/local/mysql-master/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7MySQL5.7 The file directory address of the host where the configuration file is located :/usr/local/mysql-master/conf
stay my.cnf file , Add timeout configuration .
[mysqld]
## Set up server_id, You need to be unique in the same LAN
server_id=101
## Specify the name of the database that does not need to be synchronized
binlog-ignore-db=mysql
## Turn on binary log function
log-bin=mall-mysql-bin
## Set the memory size of binary log ( Business )
binlog_cache_size=1M
## Set the binary log format to use (mixed,statement,row)
binlog_format=mixed
## Binary log expiration cleanup time . The default value is 0, Does not automatically clean up .
expire_logs_days=7
## Skip all errors encountered in master-slave replication or errors of the specified type , avoid slave End copy interrupt .
## Such as :1062 An error is a duplicate of some primary keys ,1032 The error is because the master-slave database data is inconsistent
slave_skip_errors=1062
## Set timeout
wait_timeout=1814400
interactive_timeout=1814400
Restart Docker Service and its restart MySQL service , Then check the connection time configuration :

边栏推荐
猜你喜欢

快速掌握 ASP.NET 身份认证框架 Identity - 用户注册

How to add a "security lock" to the mobile office of government and enterprises?

【阿里云服务器-安装mysql的5.6版本安装,重装】

JMeter use case
![[C language] use of library function qsort](/img/b0/6e86e31243164479b0f3d960d039ef.png)
[C language] use of library function qsort
![Web technology sharing | [Gaode map] to realize customized track playback](/img/0b/25fc8967f5cc2cea626e0b3f2b7594.png)
Web technology sharing | [Gaode map] to realize customized track playback

What is restful and what rules should be followed when designing rest APIs?

web技术分享| 【高德地图】实现自定义的轨迹回放

面对默认导入失败的情况

企业级软件开发新模式:低代码
随机推荐
STM32 ADC acquisition via DMA (HAL Library)
Summary of spark common operators
基于.NetCore开发博客项目 StarBlog - (12) Razor页面动态编译
股票在哪家的平台买比较安全呢?
0基础如何入门软件测试,能转行成功吗?
Processing source code of spark executor execution results
C#-Linq源码解析之DefaultIfEmpty
Spark's NaiveBayes Chinese text classification
Team management | how to improve the thinking skills of technical leaders?
从Application提交角度审视Executor
How to open an account in flush? Is it safe to open an account online?
Database mysql master-slave scheme
每秒處理10萬高並發訂單的樂視集團支付系統架構分享
新手必会的静态站点生成器——Gridsome
你管这破玩意儿叫高可用?
数据库mysql 主从方案
Blazor University (30)表单 —— 从 InputBase 派生
jMeter使用案例
STM32通过DMA进行ADC采集(HAL库)
【进阶自动化测试第一步】1分钟带你了解自动化测试