简体   繁体   English

从shell脚本执行时关闭mysql连接

[英]Closing mysql connection when executed from shell script

Using shell script to run mysql insert query, while running the query i am seeing connections are not being closed from shell script.使用 shell 脚本运行 mysql 插入查询,在运行查询时,我看到连接没有从 shell 脚本关闭。

Server Response after running the shell script运行 shell 脚本后的服务器响应

$ date
Tue Feb 20 15:43:58
$ netstat -alnp | grep 3306 | wc -l
26 

Where above 26 counts were like超过 26 个计数的地方就像

tcp6       0      0 192.168.10.169:31503      192.168.10.170:3306 ESTABLISHED 11603/java
$ netstat -alnp | grep 3306 | wc -l
50

Where above 50 counts were like (TIME_WAIT - 22) and (ESTABLISHED - 28)超过 50 个计数就像 (TIME_WAIT - 22) 和 (ESTABLISHED - 28)

tcp6       0      0 192.168.10.169:48308      192.168.10.170:3306 ESTABLISHED 12603/java   
tcp6       0      0 192.168.10.169:48990      192.168.10.170:3306 TIME_WAIT
$ date
Tue Feb 20 15:46:49
  1. Does mysql connection ran through shell script doesn't get closed by self通过 shell 脚本运行的 mysql 连接是否不会被自己关闭
  2. What is greater impact if shell script with mysql insert command ran via cron job at every 30 minutes如果每 30 分钟通过 cron 作业运行带有 mysql insert 命令的 shell 脚本,会有什么更大的影响

Script脚本

#!bin/bash
query="insert into table_name values ('foo', 'bar' , 123, NOW() )where column_name is NOT NUll"

mysql -u username -p password mysql  <<EOF
$query;
EOF

What will be impact on mysql maximum connections, While ran to my system i got more than 100 connections ESTABLISHED mysql 最大连接数会受到什么影响,运行到我的系统时,我建立了 100 多个连接

What STATUS value corresponds to connections ESTABLISHED ?什么STATUS值对应于connections ESTABLISHED

What was the value of什么是价值

`SHOW GLOBAL STATUS LIKE 'Max_used_connections';

I expect a small number like 1 or 2.我期望像 1 或 2 这样的小数字。

For为了

`SHOW GLOBAL STATUS LIKE 'Connections';

I expect over 100.我预计超过 100。

The commandline tool mysql will create a connection (bumping Connections and possibly increasing the "high water mark" for Max_used_connections ), do the action, then close the connection (without decreasing any STATUS ).命令行工具mysql将创建一个连接(碰撞Connections并可能增加Max_used_connections的“高水位线”),执行操作,然后关闭连接(不减少任何STATUS )。 Threads_running is also incremented and decremented. Threads_running也会递增和递减。

Your cron job should not be threatening any limitations.你的 cron 工作不应该威胁到任何限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM