当前位置:网站首页>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 :

边栏推荐
- Add a millennial sign to a number (amount in millennia)
- Test for API
- 社会担当 广汽本田“梦想童行”倡导儿童道路交通安全
- Redis implements the correct posture of the delay queue
- QT notes qmap user defined key
- 以小见大:一个领域建模的简单示例,理解“领域驱动”。
- MYSQL_ERRNO : 1292 Truncated incorrect date value At add_num :1
- Iterators and generators
- 【游标的嵌套】mysql存储过程游标的嵌套
- spark-shuffle的读数据源码分析
猜你喜欢

Team management | how to improve the thinking skills of technical leaders?

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

LETV group payment system architecture sharing for processing 100000 high concurrent orders per second
![Web technology sharing | [Gaode map] to realize customized track playback](/img/0b/25fc8967f5cc2cea626e0b3f2b7594.png)
Web technology sharing | [Gaode map] to realize customized track playback

jsp学习之(三)--------- jsp隐式对象

华为云招募工业智能领域合作伙伴,强力扶持+商业变现
![[Alibaba cloud server - install MySQL version 5.6 and reinstall]](/img/5a/50b1de5f58235f6d11f6ad1eecc455.png)
[Alibaba cloud server - install MySQL version 5.6 and reinstall]

In case of default import failure

.NET 发布和支持计划介绍

【微信小程序自定义底部tabbar】
随机推荐
Partage de l'architecture du système de paiement du Groupe letv pour traiter 100 000 commandes simultanées élevées par seconde
redis.clients.jedis.exceptions.JedisDataException ERR invalid password.
Special research on Intelligent upgrading of heavy trucks in China in 2022
数据库mysql 主从方案
Unable to connect after win10 WiFi is disconnected
jsp学习之开发环境的配置
Uniapp wechat applet obtains page QR code (with parameters)
The world's "first" IEEE privacy computing "connectivity" international standard led by insight technology was officially launched
Summary of safari compatibility issues
启牛学堂给的中信建投证券账户是不是真的?开户安全吗
JMeter use case
Problems and recovery of spark streaming checkpoint
jsp学习之(一)---------jsp概述
图计算Hama-BSP模型的运行流程
spark关于数据倾斜问题
spark Executor执行结果的处理源码
团队管理|如何提高技术 Leader 的思考技巧?
每秒處理10萬高並發訂單的樂視集團支付系統架構分享
win10的wifi断线后无法连接
[MYSQL]一台windows电脑安装多个mysql-不同版本