mysql_query
¶
Execution of MySQL queries¶
Added in version 2014.7.0.
- depends:
MySQLdb Python module
- configuration:
See
salt.modules.mysql
for setup instructions.
The mysql_query module is used to execute queries on MySQL databases. Its output may be stored in a file or in a grain.
query_id:
mysql_query.run
- database: my_database
- query: "SELECT * FROM table;"
- output: "/tmp/query_id.txt"
- saltext.mysql.states.mysql_query.__virtual__()[source]¶
Only load if the mysql module is available in __salt__
- saltext.mysql.states.mysql_query.run_file(name, database, query_file=None, output=None, grain=None, key=None, overwrite=True, saltenv=None, check_db_exists=True, client_flags=None, **connection_args)[source]¶
Execute an arbitrary query on the specified database
Added in version 2017.7.0.
- name
Used only as an ID
- database
The name of the database to execute the query_file on
- query_file
The file of mysql commands to run
- output
grain: output in a grain other: the file to store results None: output to the result comment (default)
- grain:
grain to store the output (need output=grain)
- key:
the specified grain will be treated as a dictionary, the result of this state will be stored under the specified key.
- overwrite:
The file or grain will be overwritten if it already exists (default)
- saltenv:
The saltenv to pull the query_file from
- check_db_exists:
The state run will check that the specified database exists (default=True) before running any queries
- client_flags:
A list of client flags to pass to the MySQL connection. https://dev.mysql.com/doc/internals/en/capability-flags.html
- saltext.mysql.states.mysql_query.run(name, database, query, output=None, grain=None, key=None, overwrite=True, check_db_exists=True, client_flags=None, **connection_args)[source]¶
Execute an arbitrary query on the specified database
- name
Used only as an ID
- database
The name of the database to execute the query on
- query
The query to execute
- output
grain: output in a grain other: the file to store results None: output to the result comment (default)
- grain:
grain to store the output (need output=grain)
- key:
the specified grain will be treated as a dictionary, the result of this state will be stored under the specified key.
- overwrite:
The file or grain will be overwritten if it already exists (default)
- check_db_exists:
The state run will check that the specified database exists (default=True) before running any queries
- client_flags:
A list of client flags to pass to the MySQL connection. https://dev.mysql.com/doc/internals/en/capability-flags.html