Try to set mysql user password in 2 different ways

so some versions of MySQL and/or MariaDB do not agree as to how the password
should be set?  weird, but oh well, hopefully this works everywhere...
This commit is contained in:
Lance Edgar 2020-09-30 18:19:36 -05:00
parent d744257af6
commit 96f950d958

View file

@ -70,12 +70,15 @@ def create_user(c, name, host='localhost', password=None, checkfirst=True):
if not checkfirst or not user_exists(c, name, host):
sql(c, "CREATE USER '{}'@'{}';".format(name, host))
if password:
# TODO: pretty sure this can go away, but leaving until certain
# sql(c, "SET PASSWORD FOR '{}'@'{}' = PASSWORD('{}');".format(
# name, host, password), hide=True, echo=False)
sql(c, "ALTER USER '{}'@'{}' IDENTIFIED BY '{}';".format(
# supposedly this is the new way to do it
result = sql(c, "ALTER USER '{}'@'{}' IDENTIFIED BY '{}';".format(
name, host, password),
echo=False)
echo=False, hide=True, warn=True)
if result.failed: # but this may fail for older systems
# in which case we try it the old way
sql(c, "SET PASSWORD FOR '{}'@'{}' = PASSWORD('{}');".format(
name, host, password),
echo=False, hide=True)
def db_exists(c, name):