From e048e47ad0f25af760c579373e2a9f32029a3a35 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 15 Mar 2013 10:58:27 -0400 Subject: [PATCH] .my.cnf: default to login when no user specified When using a .my.cnf file, when there is no user variable defined, default to the login user. This change has the mysql_user module behavior match the behavior of the mysql command-line client. Also adds an example .my.cnf to the docs. --- mysql_user | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mysql_user b/mysql_user index 4ca2587bbf5..7614195663a 100644 --- a/mysql_user +++ b/mysql_user @@ -91,7 +91,17 @@ requirements: [ "ConfigParser", "MySQLdb" ] author: Mark Theunissen ''' +EXAMPLES = """ +# Example .my.cnf file for setting the root password +# Note: don't use quotes around the password, because the mysql_user module +# will include them in the password but the mysql client will not +[client] +user=root +password=n<_665{vS43y +""" + import ConfigParser +import getpass try: import MySQLdb except ImportError: @@ -253,10 +263,13 @@ def load_mycnf(): passwd = config.get('client', 'pass') except (ConfigParser.NoOptionError): return False + + # If .my.cnf doesn't specify a user, default to user login name try: - creds = dict(user=config.get('client', 'user'),passwd=passwd) + user = config.get('client', 'user') except (ConfigParser.NoOptionError): - return False + user = getpass.getuser() + creds = dict(user=user,passwd=passwd) return creds # ===========================================