File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
src/pytest_databases/docker Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,21 @@ def check(_service: ServiceContainer) -> bool:
8080 else :
8181 db_name += suffix
8282
83+ # For MySQL 8, we need to handle authentication plugin compatibility
84+ exec_commands = (
85+ f'mysql --user=root --password={ root_password } -e "CREATE DATABASE { db_name } ;'
86+ f"GRANT ALL PRIVILEGES ON *.* TO '{ user } '@'%'; "
87+ )
88+
89+ # For MySQL 8, change the authentication plugin to mysql_native_password
90+ # to avoid issues with caching_sha2_password and cryptography library
91+ if "mysql:8" in image or "mysql:9" in image :
92+ exec_commands += (
93+ f"ALTER USER '{ user } '@'%' IDENTIFIED WITH mysql_native_password BY '{ password } '; "
94+ )
95+
96+ exec_commands += 'FLUSH PRIVILEGES;"'
97+
8398 with docker_service .run (
8499 image = image ,
85100 check = check ,
@@ -95,11 +110,7 @@ def check(_service: ServiceContainer) -> bool:
95110 },
96111 timeout = 60 ,
97112 pause = 0.5 ,
98- exec_after_start = (
99- f'mysql --user=root --password={ root_password } -e "CREATE DATABASE { db_name } ;'
100- f"GRANT ALL PRIVILEGES ON *.* TO '{ user } '@'%'; "
101- 'FLUSH PRIVILEGES;"'
102- ),
113+ exec_after_start = exec_commands ,
103114 transient = isolation_level == "server" ,
104115 platform = platform ,
105116 ) as service :
You can’t perform that action at this time.
0 commit comments