Locating zombie mySQL connections - mysql

I have a colleague who has been using PHP's mysql_pconnect() without my knowing it. We have had a number of instances where connections were denied due to a large number of zombie connections (per our sys admin who is currently not available).
What is the best way from the command line to locate/identify the zombie processes. I have looked at the time columns in ps aux and top but I am not sure I am getting a complete picture.
Thanks.

From MySQL console SHOW FULL PROCESSLIST; and look for these with Sleep in Command column and high values in Time. Then KILL

Related

Why does htop list so many mysql connections?

Too many mysqld connections are showing when i type htop command.
I'm using mysql pool connection for my project using nodejs sequalize ORM.
What is the reason it is showing this much connections?
The parent MySQL process spawns multiple threads which are shown by htop as separate list elements. However, a thread is not - per se - associated with an actual connection. In general, MySQL itself starts one thread per connection.
To check how many connections are used by MySQL you can run show full processlist in a mysql command line shell. For reference see the documentation of the aforementioned command.
Note well:
If you have the PROCESS privilege, you can see all threads. Otherwise, you can see only your own threads (that is, threads associated with the MySQL account that you are using).
Hope it helps.

Docker containers, memory consumption and logs

I've been trying Docker for a few days. I'm using a Drupal image (docker4drupal) which basically contains MySQL (MariaDB), PHP (php-fpm) and NGINX.
Almost everytime I do a database import to the database container, on a VPS with 512MB RAM, the container with MariaDB dies... and messages like "MySQL server has gone away" appear... And this does not happen when my VPS has 1GB o 2GB RAM.
So, this seems to be a memory problem, but I need the evidence! I don't know where is the log that tells me that my container died because wasn't enough memory.
I checked MariaDB logs but I can't find anything... it's log only say somethign like "the database was not normally shutdown" and thaen "it's starting" and then "wating for connections"...
So, independently of my MariaDB config (which is not proper for a 512MB VPS)... Where can I find explicitly the reason of why the container with the database server died?
Any help is welcome.
Thanks a lot.
PD: I execute mysql cli from the PHP container, that's why despite the database container dies I still can see the output that something wrong happened.
Could be the kernel terminating most memory-consuming process on 'lack-of-memory' event. Some entries may be there in host system log. Lack of such entries doesn't guarantee it wasn't kernel who killed your DB, though.
Exact filename depends on host system configuration (meaning the VPS, in your case). Could be /var/log/{system.log,error.log, ...}.
As long as docker container is not an isolated VM but a wrapper over kernel-driven cgroups, kernel events are handled by host system loggin daemon
Hi Beto we can see the logs in docker checkout the below commands:
The docker logs --follow command will continue streaming the new output from the container’s STDOUT and STDERR.
That is probably too much to cram in a minuscule 512MB. Do one of
Increase RAM available. ("And this does not happen when my VPS has 1GB")
Split applications across multiple tiny Dockers.
Tune each app to use less RAM. (Didn't I answer your question recently?)
How many tables do you have? Hopefully not a lot, as in https://dba.stackexchange.com/questions/60888/mysql-runs-out-of-memory-when-importing-innodb-database

How to detect what is running on MySQL every hour?

Munin showing huge spike on MySQL queries every hour but I am unable to detect what is causing this. I am running version 5.6.30.
Tried to enable slow running queries but can't find it there.
Also logged all queries and tried to see what is running on that particular time. I cannot find it.
Checked cronjobs but there wasn't anything related
Disabled almost everything on LFD & CSF
The event scheduler status is set to OFF
Is there any other way to find what is running every hour?
Munin graph showing sql queries:
You can use a shell script and put the instruccion "processlist" and send the output to a log file.
Put the delay in seconds that you want for run again the instucction.
while [true];
mysql -h localhost -u root -ppasswd < process
delay xtime
done
And the file processlist you put the instrucction "show full processlist"
I hope this help you
Regards
Some crawlers were mining data from my website. I wasn't able to detect because requests sent from a million different IPs.
Added captcha to website as human control and spikes gone.

Mysql unauthenticated users from specific machine

So one of our developers VMs is desperately trying to connect to our dev mysql server.
Looking at show full processlist shows a number of 'unauthenticated user` lines trying to connect from his specific IP.
Using ps aux | grep httpd I can see where a number of threads from httpd are running but I don't know enough to correlate what I'm seeing in the terminal with a reason his machine (not being touched) continually tries to connect.
I've looked in all crontabs and there's nothing that I can see that would do that.
Is there a way to see all processes trying to connect to a specific IP?
You can use the following to get the processes connecting to a specific ip
#netstat -ant -p | grep "ip:port"
This should give you the list, try cleaning up the processes , then do a differential analysis by disabling the crontab once and enabling them but disabling the httpd processes the next time, maybe this will help.

How do you investigate contention issues on MySQL

I am a website developer and I am being told by the server administrator that there are contention issues on the mysql database. I would like to investigate these contention issues myself and see what they are but I do not know how or where to look for contention issues. Please can you advise me where to look. Do I need to look in the logs? If so what logs and where will I find them? The database is MySQL v5.1 running on linux. I'm not sure what version yet as I don't have control panel or ssh access but I aim to get that today.
Thanks very much
Contention issues is usually a fancy way of saying there are locking problems, meaning queries get locked status.
You need to identify them and check your app for solutions.
You can run SHOW PROCESSLIST when server is busy to see what queries are currently locked.
SHOW OPEN TABLES can also help you to identify the problem and another question posted here
First you should check the mysql is running or not by using below command.
mysqladmin -u root -p status
This command will show :-
Enter password:
Uptime: 4 Threads: 1 Questions: 62 Slow queries: 0 Opens: 51 Flush tables: 1 Open tables: 60 Queries per second avg: 15.200
Also check the error type :-
http://dev.mysql.com/doc/refman/5.5/en/privilege-system.html
Maybe you should start by asking your server administrator what he/she sees that makes him/her believe that there are contention issues - they have a much better view of your DBMS than we do. And by the sound of things you are paying them for this service.
It would have been helpful if you'd said which database engine the tables are stored in: this is by far the most critical issue for contention in MySQL. You may be able to solve your problems by switching from MyISAM to Innodb.
I don't have control panel or ssh access
IME off-the-shelf control panels are fine for (very) rudimentary admin tasks, but not much use for this.
I would start by looking at the slow query log. This should be configured to log all queries - if it's not tell the admin you need it changed. Look at which queries have high lock times, then identify the lonf executing queries which are causing the high lock times. Then fix them.