From 4a73473a1e3a3eb7989085b73540f48750fc7cb5 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Wed, 13 Aug 2025 11:57:40 +0200 Subject: [PATCH 1/2] Fix structure_load/2 for MySQL 9.4+ On MySQL 9.4+, `--execute "SOURCE {path}"` is no longer supported. --- lib/ecto/adapters/myxql.ex | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index 45ef3fc28..b500df9b3 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -416,16 +416,18 @@ defmodule Ecto.Adapters.MyXQL do def structure_load(default, config) do path = config[:dump_path] || Path.join(default, "structure.sql") - args = [ - "--execute", - "SET FOREIGN_KEY_CHECKS = 0; SOURCE #{path}; SET FOREIGN_KEY_CHECKS = 1", - "--database", - config[:database] - ] - - case run_with_cmd("mysql", config, args) do - {_output, 0} -> {:ok, path} - {output, _} -> {:error, output} + with {:ok, contents} <- File.read(path) do + args = [ + "--execute", + "SET FOREIGN_KEY_CHECKS = 0; " <> contents <> "; SET FOREIGN_KEY_CHECKS = 1", + "--database", + config[:database] + ] + + case run_with_cmd("mysql", config, args) do + {_output, 0} -> {:ok, path} + {output, _} -> {:error, output} + end end end From 799db88f2dd7dcb75a23568d6d38c8612c452df1 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Wed, 13 Aug 2025 14:21:44 +0200 Subject: [PATCH 2/2] up --- lib/ecto/adapters/myxql.ex | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index b500df9b3..dc595d066 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -416,18 +416,22 @@ defmodule Ecto.Adapters.MyXQL do def structure_load(default, config) do path = config[:dump_path] || Path.join(default, "structure.sql") - with {:ok, contents} <- File.read(path) do - args = [ - "--execute", - "SET FOREIGN_KEY_CHECKS = 0; " <> contents <> "; SET FOREIGN_KEY_CHECKS = 1", - "--database", - config[:database] - ] - - case run_with_cmd("mysql", config, args) do - {_output, 0} -> {:ok, path} - {output, _} -> {:error, output} - end + case File.read(path) do + {:ok, contents} -> + args = [ + "--execute", + "SET FOREIGN_KEY_CHECKS = 0; " <> contents <> "; SET FOREIGN_KEY_CHECKS = 1", + "--database", + config[:database] + ] + + case run_with_cmd("mysql", config, args) do + {_output, 0} -> {:ok, path} + {output, _} -> {:error, output} + end + + {:error, reason} -> + {:error, "could not read #{inspect(path)}: #{:file.format_error(reason)}"} end end