salt.modules.mysql

Module to provide MySQL compatibility to salt.

In order to connect to MySQL, certain configuration is required in /etc/salt/minion on the relevant minions. Some sample configs might look like:

mysql.host: 'localhost'
mysql.port: 3306
mysql.user: 'root'
mysql.pass: ''
mysql.db: 'mysql'

You can also use a defaults file:

mysql.default_file: '/etc/mysql/debian.cnf'

Required python modules: MySQLdb

Members

connect

salt.modules.mysql.connect(**kwargs)

wrap authentication credentials here

db_check

salt.modules.mysql.db_check(name, table=None)

Repairs the full database or just a given table

CLI Example:

salt '*' mysql.db_check dbname

db_create

salt.modules.mysql.db_create(name)

Adds a databases to the MySQL server.

CLI Example:

salt '*' mysql.db_create 'dbname'

db_exists

salt.modules.mysql.db_exists(name)

Checks if a database exists on the MySQL server.

CLI Example:

salt '*' mysql.db_exists 'dbname'

db_list

salt.modules.mysql.db_list()

Return a list of databases of a MySQL server using the output from the SHOW DATABASES query.

CLI Example:

salt '*' mysql.db_list

db_optimize

salt.modules.mysql.db_optimize(name, table=None)

Optimizes the full database or just a given table

CLI Example:

salt '*' mysql.db_optimize dbname

db_remove

salt.modules.mysql.db_remove(name)

Removes a databases from the MySQL server.

CLI Example:

salt '*' mysql.db_remove 'dbname'

db_repair

salt.modules.mysql.db_repair(name, table=None)

Repairs the full database or just a given table

CLI Example:

salt '*' mysql.db_repair dbname

db_tables

salt.modules.mysql.db_tables(name)

Shows the tables in the given MySQL database (if exists)

CLI Example:

salt '*' mysql.db_tables 'database'

free_slave

salt.modules.mysql.free_slave()

Frees a slave from its master. This is a WIP, do not use.

grant_add

salt.modules.mysql.grant_add(grant, database, user, host='localhost', grant_option=False, escape=True)

Adds a grant to the MySQL server.

CLI Example:

salt '*' mysql.grant_add 'SELECT|INSERT|UPDATE|...' 'database.*' 'frank' 'localhost'

grant_exists

salt.modules.mysql.grant_exists(grant, database, user, host='localhost', grant_option=False, escape=True)

grant_revoke

salt.modules.mysql.grant_revoke(grant, database, user, host='localhost', grant_option=False)

Removes a grant from the MySQL server.

CLI Example:

salt '*' mysql.grant_revoke 'SELECT,INSERT,UPDATE' 'database.*' 'frank' 'localhost'

slave_lag

salt.modules.mysql.slave_lag()

Return the number of seconds that a slave SQL server is lagging behind the master, if the host is not a slave it will return -1. If the server is configured to be a slave for replication but slave IO is not running then -2 will be returned.

CLI Example:

salt '*' mysql.slave_lag

status

salt.modules.mysql.status()

Return the status of a MySQL server using the output from the SHOW STATUS query.

CLI Example:

salt '*' mysql.status

user_chpass

salt.modules.mysql.user_chpass(user, host='localhost', password=None, password_hash=None)

Change password for MySQL user

CLI Examples:

salt '*' mysql.user_chpass frank localhost newpassword

salt '*' mysql.user_chpass frank localhost password_hash='hash'

user_create

salt.modules.mysql.user_create(user, host='localhost', password=None, password_hash=None)

Creates a MySQL user.

CLI Examples:

salt '*' mysql.user_create 'username' 'hostname' 'password

salt '*' mysql.user_create 'username' 'hostname' password_hash='hash'

user_exists

salt.modules.mysql.user_exists(user, host='localhost')

Checks if a user exists on the MySQL server.

CLI Example:

salt '*' mysql.user_exists 'username' 'hostname'

user_grants

salt.modules.mysql.user_grants(user, host='localhost')

Shows the grants for the given MySQL user (if it exists)

CLI Example:

salt '*' mysql.user_grants 'frank' 'localhost'

user_info

salt.modules.mysql.user_info(user, host='localhost')

Get full info on a MySQL user

CLI Example:

salt '*' mysql.user_info root localhost

user_list

salt.modules.mysql.user_list()

Return a list of users on a MySQL server

CLI Example:

salt '*' mysql.user_list

user_remove

salt.modules.mysql.user_remove(user, host='localhost')

Delete MySQL user

CLI Example:

salt '*' mysql.user_remove frank localhost

version

salt.modules.mysql.version()

Return the version of a MySQL server using the output from the SELECT VERSION() query.

CLI Example:

salt '*' mysql.version