Can I find the exact query from mysql query id?
This is a part of "SHOW ENGINE INNODB STATUS" in MySQL:
MySQL thread id 1106, query id 1360 localhost 127.0.0.1 test2
---TRANSACTION 0 19491, not started, OS thread id 2960035840
Is there a way by which I can find what was the query with id 1360?
Some folks say turn on 'general log' and you'll find your query by id.
http://forums.mysql.com/read.php?22,419784,419896#msg-419896
Just added this line to my.cnf
log=/tmp/mysql_query.log
Then restarted mysql service (/etc/init.d/mysql stop /etc/init.d/mysql start)
Then tailed the log file. Seemingly there is a query id in it!
110825 15:07:49 36 Connect ***#localhost on ***
...
36 Query SELECT * FROM genre g LIMIT 0,1000
36 Quit
See also http://www.jeff-barr.com/?p=112 and http://dev.mysql.com/doc/refman/5.1/en/query-log.html
You can use the following command:
SHOW PROCESSLIST;
It will give you all currently running process with their query ID and query that is being executed.
Related
mysql server block many query, when i use show processlist, i found a simple query started 30 days ago
Command: Query
Time: 2262201
State: User sleep
Info: SELECT `abc` FROM `xxx` WHERE `a`='a' AND `b`='b';
below is mysql document explain about User sleep
https://dev.mysql.com/doc/refman/5.7/en/general-thread-states.html
The thread has invoked a SLEEP() call.
but this query string not include SLEEP function, why cause this state?
xxx is InnoDB table; mysql version is 5.7.32-log
I don't think this is a dup question as I have read other posts about error 2003 and none resolve my situation.
I have a bash script that executes mysqldump on a nightly basis against many tables in an Amazon RDS database. It has worked without issue for months, but recently, I've started seeing errors. Example results for a recent week:
Day 1: success
Day 2: success
Day 3:
TBL citygrid_state: export entire table
TBL ci_sessions: export entire table
mysqldump: Got error: 2003: Can't connect to MySQL server on 'blah' (110) when trying to connect
... wrlog crit forced halt
Day 4: success
Day 5:
TBL sparefoot.consumer_lead_action_meta: export entire table
TBL sparefoot.consumer_lead_action_type: export entire table
mysqldump: Got error: 2003: Can't connect to MySQL server on 'blah' (110) when trying to connect
... wrlog crit forced halt
Since the script works completely some nights and the calls to mysqldump work dozens of times before an error occurs, my thought is that I have a timeout problem. But where? Might it be a MySQL setting? Or does the issue lie elsewhere?
Some of the MySQL timeout settings:
connect_timeout 10
interactive_timeout 14400
net_read_timeout 30
net_write_timeout 60
wait_timeout 28800
in "show engine innodb status" i get the following row:
MySQL thread id 1, OS thread handle 0x2b0a8fef1700, query id 860436 localhost 127.0.0.1 rdsadmin cleaning up
---TRANSACTION 334275772, ACTIVE 1403158714 sec recovered trx
ROLLING BACK 2 lock struct(s), heap size 376, 1 row lock(s), undo log entries 399300
it locks a row i can't modify or delete and don't know what to do.
since i'm using aws rds i can't even restart the server
what can be done?
Probably a bit late; but here was my solution. Had to identify the actual table affected; this was done by having mysql operational, and making calls from our application that uses MySQL, then watching 'show full processlist' to see where queries were queuing up - our ncs.keywords table.
Solution was to drop that offending table, recreate the table structure, then, repopulate the table.
OS: Centos 7 .. MySQL version: 5.7
Symptom : CPU running at 100% for mysqld upon MySQL start; nothing in processlist.
Stop MySQL
#] systemctl stop mysqld
Wouldn't 'stop' so find the process and kill manually
#] kill -9 12345
Edit the MySQL config /etc/my.cnf, add line innodb_force_recovery = 3 as per documentation
Start MySQL [starts ok], CPU now at 0%. No rollback occurring.
#] systemctl start mysqld
Drop affected table ncs.keywords [we did not have to try to save our data - we repopulate it via our code]
#] mysql -u root -p
> show create table ncs.keywords [keep this syntax]
> drop table ncs.keywords
> exit
Check mysql ; restart again
#] systemctl restart mysqld
#] mysql -u root -p
> [paste the 'show create' syntax to create the fresh table again]
#] exit
Remove innodb_force_recovery = 3 from /etc/my.cnf, and restart MySQL again. CPU now at 0%, whilst not in recovery mode.
We were OK because a recovery of the data wasn't required. But you may need to dump data out of the table first.
Hope that helps [next time!].
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 ran a MySQL query from command line using the following:
nohup mysql --user=root --password=XXXXXXXXX database < report.sql > results.tab
This query is extensive (5000 lines) and running a complex search over 90,000,000 rows from 150 tables.
This query has been running for over 24 hours and has not yet finished.
Is there a way I can run status check on this running query?
try show processlist in mysql if that works.