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

 Insert picture description here

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

原网站

版权声明
本文为[The most beautiful programmer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010852153652.html