Skip to content

Commit 8576b3a

Browse files
committed
Drop support for MySQL < 8.0
MySQL 5.7 reached end-of-life in October 2023. This change: - Removes version checks and legacy SQL syntax for MySQL < 8.0 - Simplifies admin.py password change to use only ALTER USER - Simplifies test fixtures by removing conditional user creation - Updates documentation links from MySQL 5.7 to 8.0 docs
1 parent f6c9b5a commit 8576b3a

File tree

6 files changed

+34
-79
lines changed

6 files changed

+34
-79
lines changed

datajoint/admin.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from getpass import getpass
33

44
import pymysql
5-
from packaging import version
65

76
from .connection import conn
87
from .settings import config
@@ -20,13 +19,7 @@ def set_password(new_password=None, connection=None, update_config=None):
2019
logger.warning("Failed to confirm the password! Aborting password change.")
2120
return
2221

23-
if version.parse(
24-
connection.query("select @@version;").fetchone()[0]
25-
) >= version.parse("5.7"):
26-
# SET PASSWORD is deprecated as of MySQL 5.7 and removed in 8+
27-
connection.query("ALTER USER user() IDENTIFIED BY '%s';" % new_password)
28-
else:
29-
connection.query("SET PASSWORD = PASSWORD('%s')" % new_password)
22+
connection.query("ALTER USER user() IDENTIFIED BY '%s';" % new_password)
3023
logger.info("Password updated.")
3124

3225
if update_config or (

datajoint/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def conn(
9090
:param reset: whether the connection should be reset or not
9191
:param use_tls: TLS encryption option. Valid options are: True (required), False
9292
(required no TLS), None (TLS preferred, default), dict (Manually specify values per
93-
https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#encrypted-connection-options).
93+
https://dev.mysql.com/doc/refman/8.0/en/connection-options.html#encrypted-connection-options).
9494
"""
9595
if not hasattr(conn, "connection") or reset:
9696
host = host if host is not None else config["database.host"]

docs/src/query/fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ data = query.fetch(order_by='`select` desc')
8888
```
8989

9090
The `order_by` value is eventually passed to the `ORDER BY`
91-
[clause](https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html).
91+
[clause](https://dev.mysql.com/doc/refman/8.0/en/order-by-optimization.html).
9292

9393
Similarly, the `limit` and `offset` arguments can be used to limit the result to a
9494
subset of entities.

docs/src/query/operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ could contain all personnel. A project table references one person for the lead
138138
another the coordinator, both referencing the common personnel pool.
139139

140140
3. Projection can also perform calculations (as available in
141-
[MySQL](https://dev.mysql.com/doc/refman/5.7/en/functions.html)) on a single attribute.
141+
[MySQL](https://dev.mysql.com/doc/refman/8.0/en/functions.html)) on a single attribute.
142142

143143
## Aggr
144144

docs/src/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ data = query.fetch(order_by='`select` desc')
416416
```
417417

418418
The `order_by` value is eventually passed to the `ORDER BY`
419-
[clause](https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html).
419+
[clause](https://dev.mysql.com/doc/refman/8.0/en/order-by-optimization.html).
420420

421421
### Limiting results
422422

tests/conftest.py

Lines changed: 29 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import networkx as nx
1111
import pytest
1212
import urllib3
13-
from packaging import version
1413

1514
import datajoint as dj
1615
from datajoint import errors
@@ -85,51 +84,28 @@ def connection_root(connection_root_bare, prefix):
8584
dj.config["safemode"] = False
8685
conn_root = connection_root_bare
8786
# Create MySQL users
88-
if version.parse(
89-
conn_root.query("select @@version;").fetchone()[0]
90-
) >= version.parse("8.0.0"):
91-
# create user if necessary on mysql8
92-
conn_root.query(
93-
"""
94-
CREATE USER IF NOT EXISTS 'datajoint'@'%%'
95-
IDENTIFIED BY 'datajoint';
96-
"""
97-
)
98-
conn_root.query(
99-
"""
100-
CREATE USER IF NOT EXISTS 'djview'@'%%'
101-
IDENTIFIED BY 'djview';
102-
"""
103-
)
104-
conn_root.query(
105-
"""
106-
CREATE USER IF NOT EXISTS 'djssl'@'%%'
107-
IDENTIFIED BY 'djssl'
108-
REQUIRE SSL;
109-
"""
110-
)
111-
conn_root.query("GRANT ALL PRIVILEGES ON `djtest%%`.* TO 'datajoint'@'%%';")
112-
conn_root.query("GRANT SELECT ON `djtest%%`.* TO 'djview'@'%%';")
113-
conn_root.query("GRANT SELECT ON `djtest%%`.* TO 'djssl'@'%%';")
114-
else:
115-
# grant permissions. For MySQL 5.7 this also automatically creates user
116-
# if not exists
117-
conn_root.query(
118-
"""
119-
GRANT ALL PRIVILEGES ON `djtest%%`.* TO 'datajoint'@'%%'
87+
conn_root.query(
88+
"""
89+
CREATE USER IF NOT EXISTS 'datajoint'@'%%'
12090
IDENTIFIED BY 'datajoint';
12191
"""
122-
)
123-
conn_root.query(
124-
"GRANT SELECT ON `djtest%%`.* TO 'djview'@'%%' IDENTIFIED BY 'djview';"
125-
)
126-
conn_root.query(
92+
)
93+
conn_root.query(
94+
"""
95+
CREATE USER IF NOT EXISTS 'djview'@'%%'
96+
IDENTIFIED BY 'djview';
12797
"""
128-
GRANT SELECT ON `djtest%%`.* TO 'djssl'@'%%'
98+
)
99+
conn_root.query(
100+
"""
101+
CREATE USER IF NOT EXISTS 'djssl'@'%%'
129102
IDENTIFIED BY 'djssl'
130103
REQUIRE SSL;
131104
"""
132-
)
105+
)
106+
conn_root.query("GRANT ALL PRIVILEGES ON `djtest%%`.* TO 'datajoint'@'%%';")
107+
conn_root.query("GRANT SELECT ON `djtest%%`.* TO 'djview'@'%%';")
108+
conn_root.query("GRANT SELECT ON `djtest%%`.* TO 'djssl'@'%%';")
133109

134110
yield conn_root
135111

@@ -155,33 +131,19 @@ def connection_test(connection_root, prefix, db_creds_test):
155131
database = f"{prefix}%%"
156132
permission = "ALL PRIVILEGES"
157133

158-
# Create MySQL users
159-
if version.parse(
160-
connection_root.query("select @@version;").fetchone()[0]
161-
) >= version.parse("8.0.0"):
162-
# create user if necessary on mysql8
163-
connection_root.query(
164-
f"""
165-
CREATE USER IF NOT EXISTS '{db_creds_test["user"]}'@'%%'
166-
IDENTIFIED BY '{db_creds_test["password"]}';
167-
"""
168-
)
169-
connection_root.query(
170-
f"""
171-
GRANT {permission} ON `{database}`.*
172-
TO '{db_creds_test["user"]}'@'%%';
173-
"""
174-
)
175-
else:
176-
# grant permissions. For MySQL 5.7 this also automatically creates user
177-
# if not exists
178-
connection_root.query(
179-
f"""
180-
GRANT {permission} ON `{database}`.*
181-
TO '{db_creds_test["user"]}'@'%%'
182-
IDENTIFIED BY '{db_creds_test["password"]}';
183-
"""
184-
)
134+
# Create MySQL user
135+
connection_root.query(
136+
f"""
137+
CREATE USER IF NOT EXISTS '{db_creds_test["user"]}'@'%%'
138+
IDENTIFIED BY '{db_creds_test["password"]}';
139+
"""
140+
)
141+
connection_root.query(
142+
f"""
143+
GRANT {permission} ON `{database}`.*
144+
TO '{db_creds_test["user"]}'@'%%';
145+
"""
146+
)
185147

186148
connection = dj.Connection(**db_creds_test)
187149
yield connection

0 commit comments

Comments
 (0)