Skip to content

Commit 0cf7961

Browse files
committed
Update set_password to work on MySQL 8
1 parent 9c12891 commit 0cf7961

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

datajoint/admin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pymysql
22
from getpass import getpass
3+
from packaging import version
34
from .connection import conn
45
from .settings import config
56
from .utils import user_choice
@@ -16,7 +17,14 @@ def set_password(new_password=None, connection=None, update_config=None):
1617
if new_password != confirm_password:
1718
logger.warn("Failed to confirm the password! Aborting password change.")
1819
return
19-
connection.query("SET PASSWORD = PASSWORD('%s')" % new_password)
20+
21+
if version.parse(
22+
connection.query("select @@version;").fetchone()[0]
23+
) >= version.parse("5.7"):
24+
# SET PASSWORD is deprecated as of MySQL 5.7 and removed in 8+
25+
connection.query("ALTER USER user() IDENTIFIED BY '%s';" % new_password)
26+
else:
27+
connection.query("SET PASSWORD = PASSWORD('%s')" % new_password)
2028
logger.info("Password updated.")
2129

2230
if update_config or (

0 commit comments

Comments
 (0)