当前位置:网站首页>Mysql 优化
Mysql 优化
2022-07-01 08:52:00 【程序员中最靓的仔】
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
查看MySQL的连接时间配置
show global variables like “%timeout%”;

无连接可用解决
SET GLOBAL net_write_timeout = 120;
SET GLOBAL net_read_timeout = 60
接到报故,查看mysql数据库以下参数
1、innodb_buffer_pool_size
2、max_connections
该参数定义了数据缓冲区buffer pool大小,类似于oracle的db_cache_size
show global variables like ‘innodb_buffer_pool_size’;
那么如何设置该参数大小呢?首先查看运行时buffer pool相关数据指标:
show global status like ‘Innodb_buffer_pool_pages_data’;
show global status like ‘Innodb_buffer_pool_pages_total’;
show global status like ‘Innodb_page_size’;
计算Innodb_buffer_pool_pages_data/Innodb_buffer_pool_pages_total*100%
当结果 > 95% 则增加 innodb_buffer_pool_size, 建议使用物理内存的 75%
当结果 < 95% 则减少 innodb_buffer_pool_size,
建议设置大小为: Innodb_buffer_pool_pages_data* Innodb_page_size * 1.05 / (102410241024)
MySQL服务器的连接数并不是要达到最大的100%为好
show variables like ‘max_connections’;
这台MySQL服务器最大连接数是256,然后查询一下服务器响应的最大连接数:
show global status like ‘Max_used_connections’;
MySQL服务器过去的最大连接数是245,没有达到服务器连接数上限256,应该没有出现1040错误,比较理想的设置是:
Max_used_connections / max_connections * 100% ≈ 85%
最大连接数占上限连接数的85%左右,如果发现比例在10%以下,MySQL服务器连接上线就设置得过高了。
mysql数据库插入时间与系统时间相差12小时
修改catalina.sh文件
打开 tomcat目录下/bin/catalina.sh文件,在文件的开头写入:
export JAVA_OPTS=“$JAVA_OPTS -Duser.timezone=Asia/shanghai”
然后重启了tomcat。
MySQL数据库连接太多,多数Sleep
1.查看当前所有连接的详细资料: mysqladmin -uroot -proot processlist
客户端使用:
show full processlist
2、只查看当前连接数(Threads就是连接数.):
mysqladmin -uroot -proot status
客户端使用:
3.查看最大连接数
show variables like “max_connections”;
4:查看当前连接数:
show global status like ‘Max_used_connections’;
如果进程过多打印下来:
mysql -e ‘show full processlist;’ > 111
解决办法:
SHOW GLOBAL VARIABLES LIKE ‘wait_timeout’; SHOW GLOBAL VARIABLES LIKE ‘interactive_timeout’;
set global wait_timeout=100; SET GLOBAL interactive_timeout=100;
修改连接的等待时间,超过时间释放连接。
上面是实时修改重启数据库后失效
可在my.cnf中添加
wait_timeout=100
interactive_timeout=100
再次查看可能发现连接任然无法释放。需要重启数据库。
可能Shutdown mysqld失败。一直…
则重启服务器吧。
mysql数据库无响应状态了。只能强制重启了
还可以修改最大连接数(不建议):
MySQL服务器过去的最大连接数是245,没有达到服务器连接数上限256,应该没有出现1040错误,比较理想的设置是:
Max_used_connections / max_connections * 100% ≈ 85%
临时修改
set GLOBAL max_connections=1000;
永久修改:
配置/etc/my.cnf
[mysqld]新添加一行如下参数:
max_connections=1000
show variables like ‘max_connections’; 如果不是我们查看的最大1000;
这是由于mariadb有默认打开文件数限制。可以通过配置/usr/lib/systemd/system/mariadb.service来调大打开文件数目。
配置/usr/lib/systemd/system/mariadb.service
[Service]新添加两行如下参数:
LimitNOFILE=10000
LimitNPROC=10000
重新加载系统服务,并重启mariadb服务
systemctl --system daemon-reload
systemctl restart mariadb.service
边栏推荐
- It is designed with high bandwidth, which is almost processed into an open circuit?
- Shell script - special variables: shell $, $*, [email protected], $$$
- 足球篮球体育比赛比分直播平台源码/app开发建设项目
- Configuration and startup of Chang'an chain synchronization node
- 性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
- 又到年中,固定资产管理该何去何从?
- Matlab tips (23) matrix analysis -- simulated annealing
- 《单片机原理与应用》——并行IO口原理
- 3、Modbus通讯协议详解
- FreeRTOS learning easy notes
猜你喜欢

Ape anthropology topic 20 (the topic will be updated from time to time)
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code

Audio audiorecord create (I)

Nacos - 配置管理

ARM v7的体系结构A、R、M区别,分别应用在什么领域?

Principle and application of single chip microcomputer - principle of parallel IO port

FreeRTOS学习简易笔记

Dynamic proxy

Foundation: 2 The essence of image

你了解数据是如何存储的吗?(C整型和浮点型两类)
随机推荐
Computer tips
中考体育项目满分标准(深圳、安徽、湖北)
In depth learning training sample amplification and tag name modification
Jeecg restart alarm 40001
Dynamic proxy
电视机尺寸与观看距离
TV size and viewing distance
大型工厂设备管理痛点和解决方案
[untitled]
安装Oracle EE
一文纵览主流 NFT 市场平台版税、服务费设计
NIO-零拷贝
Shell脚本-while循环详解
目标检测的yolov3、4、5、6总结
《单片机原理及应用》—定时器、串行通信和中断系统
Shell script - definition, assignment and deletion of variables
The meaning of yolov5 training visualization index
又到年中,固定资产管理该何去何从?
[MFC development (17)] advanced list control list control
Introduction to R language