@ -69,6 +69,13 @@ options:
choices : [ " yes " , " no " ]
choices : [ " yes " , " no " ]
default : " no "
default : " no "
version_added : " 1.4 "
version_added : " 1.4 "
sql_log_bin :
description :
- Whether binary logging should be enabled or disabled for the connection .
required : false
choices : [ " yes " , " no " ]
default : " yes "
version_added : " 2.1 "
state :
state :
description :
description :
- Whether the user should exist . When C ( absent ) , removes
- Whether the user should exist . When C ( absent ) , removes
@ -139,6 +146,9 @@ mydb.*:INSERT,UPDATE/anotherdb.*:SELECT/yetanotherdb.*:ALL
# Example using login_unix_socket to connect to server
# Example using login_unix_socket to connect to server
- mysql_user : name = root password = abc123 login_unix_socket = / var / run / mysqld / mysqld . sock
- mysql_user : name = root password = abc123 login_unix_socket = / var / run / mysqld / mysqld . sock
# Example of skipping binary logging while adding user 'bob'
- mysql_user : name = bob password = 12345 priv = * . * : USAGE state = present sql_log_bin = no
# Example .my.cnf file for setting the root password
# Example .my.cnf file for setting the root password
[ client ]
[ client ]
@ -479,6 +489,7 @@ def main():
check_implicit_admin = dict ( default = False , type = ' bool ' ) ,
check_implicit_admin = dict ( default = False , type = ' bool ' ) ,
update_password = dict ( default = " always " , choices = [ " always " , " on_create " ] ) ,
update_password = dict ( default = " always " , choices = [ " always " , " on_create " ] ) ,
config_file = dict ( default = " ~/.my.cnf " ) ,
config_file = dict ( default = " ~/.my.cnf " ) ,
sql_log_bin = dict ( default = True , type = ' bool ' ) ,
ssl_cert = dict ( default = None ) ,
ssl_cert = dict ( default = None ) ,
ssl_key = dict ( default = None ) ,
ssl_key = dict ( default = None ) ,
ssl_ca = dict ( default = None ) ,
ssl_ca = dict ( default = None ) ,
@ -502,6 +513,7 @@ def main():
ssl_key = module . params [ " ssl_key " ]
ssl_key = module . params [ " ssl_key " ]
ssl_ca = module . params [ " ssl_ca " ]
ssl_ca = module . params [ " ssl_ca " ]
db = ' mysql '
db = ' mysql '
sql_log_bin = module . params [ " sql_log_bin " ]
config_file = os . path . expanduser ( os . path . expandvars ( config_file ) )
config_file = os . path . expanduser ( os . path . expandvars ( config_file ) )
if not mysqldb_found :
if not mysqldb_found :
@ -520,6 +532,9 @@ def main():
except Exception , e :
except Exception , e :
module . fail_json ( msg = " unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s " % ( config_file , e ) )
module . fail_json ( msg = " unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s " % ( config_file , e ) )
if not sql_log_bin :
cursor . execute ( " SET SQL_LOG_BIN=0; " )
if priv is not None :
if priv is not None :
try :
try :
mode = get_mode ( cursor )
mode = get_mode ( cursor )