当前位置:网站首页>MySQL optimization
MySQL optimization
2022-07-01 08:54:00 【The most beautiful programmer】
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
see MySQL Connection time configuration
show global variables like “%timeout%”;

No connection available
SET GLOBAL net_write_timeout = 120;
SET GLOBAL net_read_timeout = 60
Report of accident received , see mysql The database has the following parameters
1、innodb_buffer_pool_size
2、max_connections
This parameter defines the data buffer buffer pool size , Be similar to oracle Of db_cache_size
show global variables like ‘innodb_buffer_pool_size’;
So how to set the parameter size ? First look at the runtime buffer pool Related data indicators :
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’;
Calculation Innodb_buffer_pool_pages_data/Innodb_buffer_pool_pages_total*100%
When it turns out > 95% Increase innodb_buffer_pool_size, It is recommended to use physical memory 75%
When it turns out < 95% Then reduce innodb_buffer_pool_size,
It is recommended to set the size to : Innodb_buffer_pool_pages_data* Innodb_page_size * 1.05 / (102410241024)
MySQL The number of connections to the server is not intended to reach the maximum 100% For good
show variables like ‘max_connections’;
The machine MySQL The maximum number of server connections is 256, Then query the maximum number of connections that the server responds to :
show global status like ‘Max_used_connections’;
MySQL The maximum number of connections to the server in the past was 245, The maximum number of server connections has not been reached 256, There should be no 1040 error , The ideal setting is :
Max_used_connections / max_connections * 100% ≈ 85%
The maximum number of connections accounts for... Of the maximum number of connections 85% about , If it turns out that the ratio is 10% following ,MySQL The server connection is set too high .
mysql There is a difference between the database insertion time and the system time 12 Hours
modify catalina.sh file
open tomcat Under the table of contents /bin/catalina.sh file , Write... At the beginning of the file :
export JAVA_OPTS=“$JAVA_OPTS -Duser.timezone=Asia/shanghai”
And then it rebooted tomcat.
MySQL Too many database connections , Most of the Sleep
1. View details of all current connections : mysqladmin -uroot -proot processlist
Client side usage :
show full processlist
2、 Only view the current number of connections (Threads Is the number of connections .):
mysqladmin -uroot -proot status
Client side usage :
3. See the maximum number of connections
show variables like “max_connections”;
4: View the current number of connections :
show global status like ‘Max_used_connections’;
If there are too many processes, print them out :
mysql -e ‘show full processlist;’ > 111
terms of settlement :
SHOW GLOBAL VARIABLES LIKE ‘wait_timeout’; SHOW GLOBAL VARIABLES LIKE ‘interactive_timeout’;
set global wait_timeout=100; SET GLOBAL interactive_timeout=100;
Modify the waiting time of the connection , Time expired to release the connection .
The above is the failure after real-time modification and database restart
Can be found in my.cnf Add
wait_timeout=100
interactive_timeout=100
If you check again, you may find that the connection still cannot be released . Need to restart the database .
Probably Shutdown mysqld Failure . always …
Restart the server .
mysql The database is not responding . Can only be forced to restart
You can also modify the maximum number of connections ( Don't suggest ):
MySQL The maximum number of connections to the server in the past was 245, The maximum number of server connections has not been reached 256, There should be no 1040 error , The ideal setting is :
Max_used_connections / max_connections * 100% ≈ 85%
Temporary modification
set GLOBAL max_connections=1000;
Permanent modification :
To configure /etc/my.cnf
[mysqld] Add a new line as follows :
max_connections=1000
show variables like ‘max_connections’; If it's not the biggest one we've seen 1000;
This is because mariadb There is a default limit on the number of open files . Can be configured by /usr/lib/systemd/system/mariadb.service To increase the number of open files .
To configure /usr/lib/systemd/system/mariadb.service
[Service] Add two new lines as follows :
LimitNOFILE=10000
LimitNPROC=10000
Reload system services , And restart mariadb service
systemctl --system daemon-reload
systemctl restart mariadb.service
边栏推荐
- Differences among tasks, threads and processes
- 公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度
- Redis——Lettuce连接redis集群
- 软件工程师面试刷题网站、经验方法
- Only in China! Alicloud container service enters the Forrester leader quadrant
- LogBack
- 用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
- 5mo3 UHI HII HII 17mn4 19Mn6 executive standard
- 1.jetson与摄像头的对接
- IT 技术电子书 收藏
猜你喜欢

Matlab tips (16) consistency verification of matrix eigenvector eigenvalue solution -- analytic hierarchy process

5mo3 UHI HII HII 17mn4 19Mn6 executive standard

为什么LTD独立站就是Web3.0网站!

Nacos - Configuration Management

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

How to manage fixed assets well? Easy to point and move to provide intelligent solutions

如何解决固定资产管理和盘点的难题?

Matlab tips (23) matrix analysis -- simulated annealing

Only in China! Alicloud container service enters the Forrester leader quadrant

3. Detailed explanation of Modbus communication protocol
随机推荐
如何做好固定资产管理?易点易动提供智能化方案
Shell script - array definition and getting array elements
Centos7 shell脚本一键安装jdk、mongo、kafka、ftp、postgresql、postgis、pgrouting
Insert mathematical formula in MD document and mathematical formula in typora
[MFC development (16)] tree control
一文纵览主流 NFT 市场平台版税、服务费设计
Shell脚本-数组定义以及获取数组元素
yolov5训练可视化指标的含义
3. Detailed explanation of Modbus communication protocol
易点易动助力企业设备高效管理,提升设备利用率
Introduction to R language
Shell脚本-位置参数(命令行参数)
How can enterprises and developers take the lead in the outbreak of cloud native landing?
IT 技术电子书 收藏
Advanced level of C language pointer (Part 1)
Shell脚本-while循环详解
It technology ebook collection
JCL 和 SLF4J
TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
足球篮球体育比赛比分直播平台源码/app开发建设项目