As part of my fundamentals package, I’ve added a command-line tool call mysqlSucker. Given a directory of MySQL scripts, mysqlSucker can execute the script files and process them according to their success or failure status.
Use pip install fundamentals to install mysqlSucker.
Setup Your MySQL Login Path
Before you begin you will need to run the following code once to set a login-path for your mysql server (> v5.6.6):
mysql_config_editor set --login-path=<uniqueLoginName> --host=localhost --user=<myUsername> --password
This stores your credentials in an encrypted file located at ~/.mylogin.cnf. You can use mysql_config_editor print --all to see all of the login-paths set.
mysqlSucker Usage
Usage:
mysqlSucker <pathToDirectory> <loginPath> <databaseName> [-s successRule -f failureRule]
pathToDirectory path to the directory containing the sql scripts to run (scripts must have `.sql` extension)
loginPath the local-path as set with `mysql_config_editor` (`mysqlSucker -h` for more details)
databaseName the name of the database to execute the scripts within
Options:
-h, --help show this help message
-s successRule, --success successRule what to do if script succeeds. Default *None* [None|delete|subFolderName]
-f failureRule, --failure failureRule what to do if script fails. Default *None* [None|delete|subFolderName]
Examples
To simply execute the scripts in a directory run:
mysqlSucker /path/to/scriptdir myLoginPath myDatabaseName
To delete script after they have executed successfully:
mysqlSucker /path/to/scriptdir myLoginPath myDatabaseName -s delete
To move successful script to a passed sub-directory of /path/to/scriptdir and failed scripts to a failed sub-directory
mysqlSucker /path/to/scriptdir myLoginPath myDatabaseName -s pass -f failed