oak-repeat-query
NAME
oak-repeat-query: repeat query execution until some condition holdsSYNOPSIS
Repeat DELETE query until no more rows are affected, verbose:oak-repeat-query --user=root --socket=/tmp/mysql.sock --database=sakila -e "DELETE FROM sakila.film_actor LIMIT 100" -vRepeat UPDATE query until no more rows are affected, sleep 1 second between iterations, use defaults file:
oak-repeat-query --defaults-file=/home/myuser/.my-oak.cnf --database=sakila -e "UPDATE film SET title = LEFT(title, 20) WHERE CHAR_LENGTH(title) > 20" --sleep-time=1000 -vRepeat a query for 200 times, sleep 1 second between iterations:
oak-repeat-query --defaults-file=/home/myuser/.my-oak.cnf --database=sakila -e "SELECT * FROM hot_table WHERE ts BETWEEN NOW() - INTERVAL 1 MINUTE AND NOW()" --sleep-time=1000 --max-iterations=200Repeat a query for 2 minutes, sleep 1 second between iterations:
oak-repeat-query --defaults-file=/home/myuser/.my-oak.cnf --database=sakila -e "SELECT * FROM hot_table WHERE ts BETWEEN NOW() - INTERVAL 1 MINUTE AND NOW()" --sleep-time=1000 --max-seconds=120
DESCRIPTION
This tool invokes given query until no more rows are affected, a number of iterations is reached, or certain time has passed.
Two required options for this tool are --database (database to connect to) and --execute (query to execute).
oak-repeat-query terminates under the following conditions:
- If --max-iterations is specified, and number of iteration exceeds given value, the tool terminates.
- If --max-seconds is specified, and the total runtime (including sleep time) exceeds given value, the tool terminates.
- If none of the above are defined, the tool terminates when no rows are affected by given query.
- If Ctrl-C is hit, the tool terminates.
There is no cleanup code for termination.
OPTIONS
--ask-passPrompt for password.
-d DATABASE, --database=DATABASEDatabase name (required)
--debugPrint stack trace on error.
--defaults-file=DEFAULTS_FILERead from MySQL configuration file. Overrides --user, --password, --socket, --port.
Configuration needs to be in the following format:
[client]
user=my_user
password=my_pass
socket=/tmp/mysql.sock
port=3306
Query to execute (required)
-H HOST, --host=HOSTMySQL host (default: localhost)
--max-iterations=MAX_ITERATIONSMaximum number of iterations to execute
--max-seconds=MAX_SECONDSMaximum number of seconds (clock time) to run
-p PASSWORD, --password=PASSWORDMySQL password
-P PORT, --port=PORTTCP/IP port (default: 3306)
-s SLEEP_TIME, --sleep-time=SLEEP_TIMENumber of milliseconds to sleep between query executions (default: 0)
--sleep-ratio=SLEEP_RATIORatio of sleep time to execution time. Default: 0
-S SOCKET, --socket=SOCKETMySQL socket file. Only applies when host is localhost
-u USER, --user=USERMySQL user
-v, --verbosePrint user friendly messages
ENVIRONMENT
Requires MySQL 5.0 or newer, python 2.3 or newer. python-mysqldb must be installed in order to use this tool. You canapt-get install python-mysqldbor
yum install mysql-python
SEE ALSO
oak-chunk-update
LICENSE
This tool is released under the BSD license.Copyright (c) 2008 - 2010, Shlomi Noach All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.