1

I'm running a mysql-query from a bash shell which should write the result into a file. The thingy looks like this (simplified a bit):

   mysql -uname -ppwd wmap -e "select netpoints.bssid,netpoints.lat,netpoints.lon from netpoints,users WHERE ((users.flags & 1 = 1) AND users.idx=netpoints.userid) OR (netpoints.source=5);" >db/db.csv

The query itself is OK and worked fine, but until some time execution of the script fails with

   line 1: 11427 Killed 

So...how can I avoid that the query is terminated this way? The result would be a big amounto f data and the query needs a really long time to execute but that's OK as long as there will be an result.

(Add the command and error message into code tags)

3
  • was it killed manually? is there more debugging info from mysql logs?
    – user972946
    Jan 28, 2014 at 21:20
  • No, it is not killed manually - I guess it happens because the query is too complex/results in too much data
    – Elmi
    Jan 28, 2014 at 21:21
  • did you run the command through ssh with time-out issue?
    – BMW
    Jan 29, 2014 at 2:51

3 Answers 3

7

By default the entire result set is fetched in memory. If that becomes to much, the mysql client will be killed. You can start the mysql client with the --quick option to prevent this:

   mysql --quick -uname -ppwd wmap -e  ... 
1
  • Oh, nice one! Didn't know that :-) I guess I never read the cli's manpage. +1
    – jweyrich
    Jan 31, 2014 at 1:14
1

You might be hitting a timeout in MySQL. You may want to check your MySQL slow query log to see if that's the case. If so, you may want to look at optimizing the query if possible, or perhaps increasing the timeouts in MySQL (http://www.rackspace.com/knowledge_center/article/how-to-change-the-mysql-timeout-on-a-server for info on how to do this).

0

In this case you should use LIMIT to split your query results.

How many rows is your query supposed to return?

It seems that it's going to result in hundreds of thousands (or millions) of rows, consuming too much memory. You can check this with SELECT count(1) FROM netpoints WHERE <suppressed>;

If that's not the issue, it's likely that your connection to MySQL is becoming idle and therefore being automatically closed by mysqld. To fix this, you can change your script to issue periodic commands, or increase the MySQL wait_timeout configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.