I found that some connection got unclosed after the execution of command from Mysql server.
How can I configure my Mysql server so that I can close them all after executing a command?
if you can get the process_id inside mysql you can kill the process. Killing any process should work (though it will create a new connection next time you send a command).
mysql> SHOW PROCESSLIST; -- or SHOW FULL PROCESSLIST
mysql> KILL process_number;
Configure the wait_timeout variable to something soon enough, for example 30 seconds
Related
Hi all I have recently noticed that in my mysql.log file that it is getting flooded with the below messages.
I am not sure why the debian-sys-maint keeps making this connection and then quitting, it has all the right credentials so it is not a permissions issue to my understanding.
Does anyone have any ideas thank you
150903 12:12:17 192 Connect debian-sys-maint#localhost on
192 Quit
150903 12:12:18 193 Connect debian-sys-maint#localhost on
193 Quit
150903 12:12:19 194 Connect debian-sys-maint#localhost on
194 Quit
The log is correct.
Connection to MySql will quit after connecting and executing a query.
You might keep the connection alive, but in case you are executing into something that starts & terminates with a single HTTP request/response (like a PHP script), then it's normal that the connection to MySql gets closed at the end of the script.
Seeing that log just means that global general_log is active (instruction SET global general_log = on; executed in the MySql console).
If you don't want those logs just set general_log to off.
Otherwise, I would wonder more why there is no SQL query logged in between the Connect and the Quit.
I am uploading data to a MySQL database from a shell script (from cron) every 5 minutes.
But if my connection is down, it does not insert it in to my database.
I would like the script to try to insert again and again (for example every 30 minutes) until it is successful.
And if my connection is down more than 5 minutes, I would like to these requests to stand in a queue and proceed when I have connection again.
How can I do that?
Example code:
#!/bin/bash
cputemp=$(somecommands...)
/usr/bin/mysql -h 127.0.0.1 -u admin -pwpassword -e "USE logs; INSERT INTO cpu (cputemp) VALUES ('$cputemp');"
You'd do it by writing in that logic into your code. Should be fairly easy detect it couldn't detect, have it sleep, then try again.
Is there some configuration that can be done at MySQL side to automatically kill or timeout queries that are extremely slow, say 100 seconds.
You can list all your MySQL queries by the following command:
$ mysqladmin processlist
so you can run some script which will parse that list and it'll kill the specific query.
In example, you can run some script in any language via cron to periodically check for the long queries, e.g.:
$result = mysql_query("SHOW FULL PROCESSLIST");
while ($row=mysql_fetch_array($result)) {
$process_id=$row["Id"];
if ($row["Time"] > 200 ) {
$sql="KILL $process_id";
mysql_query($sql);
}
}
Another example:
mysql> select concat('KILL ',id,';') from information_schema.processlist
where user='root' and time > 200 into outfile '/tmp/a.txt';
mysql> source /tmp/a.txt;
Related:
How do I kill all the processes in Mysql "show processlist"?
Read more:
http://www.mysqlperformanceblog.com/
Starting with MySQL 5.1 you can create a stored procedure to query the information_schmea.PROCESSLIST table for all queries that match your criteria ("long running time" in your case). Upon querying processlist table, you can simply iterate over a cursor to kill the running query processes that exceeds your timeout criteria.
Take a look at the following example: Procedure to find and terminate all non-SUPER and "system account" queries running longer than N seconds
http://forge.mysql.com/tools/tool.php?id=106
You should checkout the command pt-kill of percona toolkit
I'm trying to create database by using:
create database test;
It seems so simple but when I hit enter, it only waits. No error message, just nothing. There is an another database working for a live application, so I can not restart the mysql service. Mysql must be alive all the time. Is there anything I can do about this situation? What is the reason?
Output:
root#delta-dbs1:/# mysql -u mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 124011
Server version: 5.1.30-ndb-6.3.20-cluster-gpl MySQL Cluster Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database test_wips;
and nothing comes after it. It only hangs. And response to ping is also good. There is no problem with network, because my applications are getting data beatifully from the other databases which were created before. My problem is, i cant create or drop any database.
Thanks in advance.
Probably the other application is slowing down your server with a query. You need to take a look at the slow query log to check which one.
Please, print console output for
$ mysql -u username --password=HIDDEN_PASSWORD --port=330X --host=HOSTNAME
mysql> create database `test`;
mysql>
Maybe your software or network stucks? How do you know that it is exactly MySQL's problem?
You also can try diagnose your network problems using this commands:
$ traceroute HOST
$ ping HOST
I'm running mysql on Debian.
Is there a way to monitor mysql and restart it automatically if it locks up? For example sometimes the server starts to take 100% of cpu and starts running very slowly. If I restart mysql, things clear up and the server starts working fine, but I'm not always present to restart it manually.
Is there a way to monitor mysql and if the cpu is above 95% for more than 10 minutes straight then then mysql will automatically be restarted
You can write a cronjob to use
show processlist;
show processlist will return column Time and Id,
you can add more logic to check,
like query stuck for more than 600 seconds and the query is SELECT,
you can use Id value to perform kill $id;
This is safer than blindly restarting your server.
And if you have segregate between read/write (meaning read only SQL will use user with read privileges only), this can even simpler.
Use this bash script to check every minute.
#!/bin/bash
#Checking whether MySQL is alive or not
if mysqladmin ping | grep "alive"; then
echo "MySQL is up"
else
sudo service mysql restart
fi
`