当前位置:网站首页>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
边栏推荐
- 【面试必刷101】链表
- factory type_ Id:: create process resolution
- IT 技术电子书 收藏
- 大型工厂设备管理痛点和解决方案
- 猿人学第20题(题目会不定时更新)
- Principle and application of single chip microcomputer - principle of parallel IO port
- Shell script - array definition and getting array elements
- TV size and viewing distance
- VSYNC+三重缓存机制+Choreographer
- Serial port to WiFi module communication
猜你喜欢

中小企业固定资产管理办法哪种好?

《单片机原理与应用》——并行IO口原理

Jetson Nano 安装TensorFlow GPU及问题解决
![[MFC development (16)] tree control](/img/b9/1de4330c0bd186cfe062b02478c058.png)
[MFC development (16)] tree control

Do you know how data is stored? (C integer and floating point)

一文纵览主流 NFT 市场平台版税、服务费设计
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

嵌入式工程师面试题3-硬件

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?

Insert mathematical formula in MD document and mathematical formula in typora
随机推荐
Shell script - array definition and getting array elements
Shell script -while loop explanation
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
VSYNC+三重缓存机制+Choreographer
IT 技术电子书 收藏
Shell script case in and regular expressions
Principle and application of single chip microcomputer - principle of parallel IO port
Nacos - 服务发现
Pain points and solutions of fixed assets management of group companies
Jeecg restart alarm 40001
Nacos - 配置管理
如何高效拉齐团队认知
JCL and slf4j
Shell脚本-while循环详解
JCL 和 SLF4J
LogBack
安装Oracle EE
Common interview questions for embedded engineers 2-mcu_ STM32
固定资产管理系统让企业动态掌握资产情况
中考体育项目满分标准(深圳、安徽、湖北)