Find failed requests and queries that go into deadlock - mysql

Some of the requests to my application fail every day. I want to know every time which all queries went into deadlock.
I am running MySQL 5.6 on AWS.
FYI, tool suggestions are also welcome.

Related

Deadlock appearing intermittently in mysql

I am running a multiple spring boot micro-services. All my services connect to database using spring-data(JPA repositories). Unfortunately due to particular API, deadlocks are occurring in database server. As per the primary investigation I feel the deadlock has happened because two transactions trying to modify the same table resource. Should any of it do with isolation levels of transaction.
Yet, I am not able to make concrete conclusion out of it. Can someone please figure out the root cause of this deadlock?
Please see the attached database logs of transactions leading to deadlock in below pictures.
Transaction1
Transaction2

Laravel connection database issue because of blocking

There is laravel API that connects with Amazon RDS. Usually, all works well, but sometimes API loses connections with the database because of locking it. It occurs at a different time, sometimes once a week, sometimes twice a day. When it occurs, several crons are running and API also processes user requests. I've added SQL logging, but can't find something strange there.(maybe because the SQL queries didn't finish and weren't in logs). Any suggestions on how to catch this issue?
Laravel 5.4, MYSQL 5.7

MySQL Power Outage Affecting MySQL Server - Shuts Down On Its Own

I am new to dealing with mysql settings and admin type issues. About 4-5 hours ago, I had two power outages within 30 minutes of eachother. As a result, my computer shutdown both times, while in the middle of what I can only assume was a around 20-30 commands on mysql at the time. After the first, mysql was unaffected. But after the second, something happened. MySQL Server cannot remain open for more than a few seconds at a time (before the outage, this was not a problem). I am running MySQL Server 5.1.
I can manually start MySQL server using the admin command line (I am running this on Windows): net start mysql. I get a message saying "The MySQL service was started successfully". Then I run a command or (max) two, and then again everything stops working with a 2013 "Lost connection to MYSQL server during query". Then I have to do restart the MySQL Server all over again.
I have some important data in the database which I cannot reach because the connection times out before I can get it out. Is there a way I can fix this connection problem easily? I know my data is in there, because I have gotten a fair amount of it out.
Any help would be appreciated. Please let me know what other information you might need, and how I can get it. I have been trying to find the error log for mysql, and have not found it yet.
And, yes, if I get through this, and even if I dont, I will make sure to create a system to update the data on a regular basis so these types of failures aren't so catastrophic in the future.
Thanks in advance

How to find CPU utilazetion of mysql RDS instance

How to find which process/query consume CPU in amazon mysql RDS instance? I have medium instance on amazon RDS of mysql, and It is working smoothly previously, but since yesterday Its throwing error 'connection timeout' while accessing RDS instance. When I checked cloud watch, It shows me high CPU utilization during that period. Now I want to check what is the problem? So, can some one tell me how to check it?
thanks
use 'show processlist' in mysql. with this you can see which queries are in what state, doing what, since when
also check slow query log:
http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html
Using show process list, you can see only current running thread info, but as per context of your query, you want to see the historical status. You can achieve it via enabling the slow query log and setting long query time to 1 second. You can pass slow query logs to cloud watch and can set alerts according to your db system loads and types of queries.

Will mysql somehow rerun killed query behind my back?

I ran a very unique experimental long query about 1 week ago from Sequel Pro against a MySQL 5.5 DB. The query is not used in any codes; just a manual one. I remember I killed it after only a few seconds. Then in the last few days, the DBA keeps finding the exact same query was started again after one being killed. The DBA has verified the query was killed at the time he tried. My workstation has been rebooted at least once and moved out of network connection many times since I first ran that query manually. Sequel Pro had no connection to any DB when one of this rerun occurred. And there seems nothing else in my workstation that would trigger that.
My question: is there some way that the query can get stuck in some server-side job/run list and not being killed properly but get rerun?
Found the cause. A DBA has cron script running in the background looking for slow queries in the slow query log and try to run explain on the query! Apparently the slow queries get rerun again and again.