Module to provide MySQL compatibility to salt.
depends: |
|
---|---|
configuration: | 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'
mysql.unix_socket: '/tmp/mysql.sock'
You can also use a defaults file: mysql.default_file: '/etc/mysql/debian.cnf'
|
Repairs the full database or just a given table
CLI Example:
salt '*' mysql.db_check dbname
Adds a databases to the MySQL server.
CLI Example:
salt '*' mysql.db_create 'dbname'
Checks if a database exists on the MySQL server.
CLI Example:
salt '*' mysql.db_exists 'dbname'
Return a list of databases of a MySQL server using the output from the SHOW DATABASES query.
CLI Example:
salt '*' mysql.db_list
Optimizes the full database or just a given table
CLI Example:
salt '*' mysql.db_optimize dbname
Removes a databases from the MySQL server.
CLI Example:
salt '*' mysql.db_remove 'dbname'
Repairs the full database or just a given table
CLI Example:
salt '*' mysql.db_repair dbname
Shows the tables in the given MySQL database (if exists)
CLI Example:
salt '*' mysql.db_tables 'database'
Frees a slave from its master. This is a WIP, do not use.
CLI Example:
salt '*' mysql.free_slave
Retrieves the master status from the minion.
CLI Example:
salt '*' mysql.get_master_status
Retrieves the slave status from the minion.
Returns:
{'host.domain.com': {'Connect_Retry': 60,
'Exec_Master_Log_Pos': 107,
'Last_Errno': 0,
'Last_Error': '',
'Last_IO_Errno': 0,
'Last_IO_Error': '',
'Last_SQL_Errno': 0,
'Last_SQL_Error': '',
'Master_Host': 'comet.scion-eng.com',
'Master_Log_File': 'mysql-bin.000021',
'Master_Port': 3306,
'Master_SSL_Allowed': 'No',
'Master_SSL_CA_File': '',
'Master_SSL_CA_Path': '',
'Master_SSL_Cert': '',
'Master_SSL_Cipher': '',
'Master_SSL_Key': '',
'Master_SSL_Verify_Server_Cert': 'No',
'Master_Server_Id': 1,
'Master_User': 'replu',
'Read_Master_Log_Pos': 107,
'Relay_Log_File': 'klo-relay-bin.000071',
'Relay_Log_Pos': 253,
'Relay_Log_Space': 553,
'Relay_Master_Log_File': 'mysql-bin.000021',
'Replicate_Do_DB': '',
'Replicate_Do_Table': '',
'Replicate_Ignore_DB': '',
'Replicate_Ignore_Server_Ids': '',
'Replicate_Ignore_Table': '',
'Replicate_Wild_Do_Table': '',
'Replicate_Wild_Ignore_Table': '',
'Seconds_Behind_Master': 0,
'Skip_Counter': 0,
'Slave_IO_Running': 'Yes',
'Slave_IO_State': 'Waiting for master to send event',
'Slave_SQL_Running': 'Yes',
'Until_Condition': 'None',
'Until_Log_File': '',
'Until_Log_Pos': 0}}
CLI Example:
salt '*' mysql.get_slave_status
Adds a grant to the MySQL server.
For database, make sure you specify database.table or database.*
CLI Example:
salt '*' mysql.grant_add 'SELECT,INSERT,UPDATE,...' 'database.*' 'frank' 'localhost'
Checks to see if a grant exists in the database
CLI Example:
salt '*' mysql.grant_exists 'SELECT,INSERT,UPDATE,...' 'database.*' 'frank' 'localhost'
Removes a grant from the MySQL server.
CLI Example:
salt '*' mysql.grant_revoke 'SELECT,INSERT,UPDATE' 'database.*' 'frank' 'localhost'
Retrieves the processlist from the MySQL server via "SHOW FULL PROCESSLIST".
CLI Example:
salt '*' mysql.processlist
Run an arbitrary SQL query and return the results or the number of affected rows.
CLI Examples:
salt '*' mysql.query mydb "UPDATE mytable set myfield=1 limit 1"
returns: {'query time': {'human': '39.0ms', 'raw': '0.03899'},
'rows affected': 1L}
salt '*' mysql.query mydb "SELECT id,name,cash from users limit 3"
returns: {'columns': ('id', 'name', 'cash'),
'query time': {'human': '1.0ms', 'raw': '0.001'},
'results': ((1L, 'User 1', Decimal('110.000000')),
(2L, 'User 2', Decimal('215.636756')),
(3L, 'User 3', Decimal('0.040000'))),
'rows returned': 3L}
salt '*' mysql.query mydb "INSERT into users values (null,'user 4', 5)"
returns: {'query time': {'human': '25.6ms', 'raw': '0.02563'},
'rows affected': 1L}
salt '*' mysql.query mydb "DELETE from users where id = 4 limit 1"
returns: {'query time': {'human': '39.0ms', 'raw': '0.03899'},
'rows affected': 1L}
Jinja Example:
Run a query on "mydb" and use row 0, column 0's data.
{{ salt['mysql.query']("mydb","SELECT info from mytable limit 1")['results'][0][0] }}
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
Return the status of a MySQL server using the output from the SHOW STATUS query.
CLI Example:
salt '*' mysql.status
Change password for MySQL user
CLI Examples:
salt '*' mysql.user_chpass frank localhost newpassword
salt '*' mysql.user_chpass frank localhost password_hash='hash'
Creates a MySQL user.
CLI Examples:
salt '*' mysql.user_create 'username' 'hostname' 'password'
salt '*' mysql.user_create 'username' 'hostname' password_hash='hash'
Checks if a user exists on the MySQL server.
CLI Example:
salt '*' mysql.user_exists 'username' 'hostname' 'password'
salt '*' mysql.user_exists 'username' 'hostname' password_hash='hash'
Shows the grants for the given MySQL user (if it exists)
CLI Example:
salt '*' mysql.user_grants 'frank' 'localhost'
Get full info on a MySQL user
CLI Example:
salt '*' mysql.user_info root localhost
Return a list of users on a MySQL server
CLI Example:
salt '*' mysql.user_list
Delete MySQL user
CLI Example:
salt '*' mysql.user_remove frank localhost
Return the version of a MySQL server using the output from the SELECT VERSION() query.
CLI Example:
salt '*' mysql.version