From 75c610aac316e6fafa86028371520203093fe047 Mon Sep 17 00:00:00 2001 From: Peter Baker Date: Wed, 26 Aug 2020 11:48:30 +0100 Subject: [PATCH 01/15] mysql@5.7: Improve warnings when data directory is present. Users are already warned about config files, warn users about conflicting data directory too. --- Formula/mysql@5.7.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index a18e04573c64f..ff5c635be89a9 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -105,6 +105,13 @@ def caveats To connect run: mysql -uroot EOS + if datadir == (var/"mysql") && datadir.exist? + s += <<~EOS + + #{datadir} from another install may interfere with a Homebrew-built + server starting up correctly. + EOS + end if (my_cnf = ["/etc/my.cnf", "/etc/mysql/my.cnf"].find { |x| File.exist? x }) s += <<~EOS From b9194c5dccdaf32f4363ff00eff9d7c47f7e0328 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Fri, 28 Aug 2020 19:12:30 +0100 Subject: [PATCH 02/15] Pseudocode of what this should do. --- Formula/mysql@5.7.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index ff5c635be89a9..aa7a08cdbcc8f 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -86,6 +86,14 @@ def install end def post_install + if datadir_is_already_mysql5.7 + do_nothing + elsif datadir_is_mysql8 + choose_mysql5.7_specific_datadir + elsif there_is_no_datadir + choose_mysql5.7_specific_datadir + end + # Make sure the datadir exists datadir.mkpath unless (datadir/"mysql/general_log.CSM").exist? From 4497d805c008956ca7ca56dcc1421cb1d93c08d4 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Fri, 28 Aug 2020 19:15:02 +0100 Subject: [PATCH 03/15] Add note about 5.6 changes which are also required. --- Formula/mysql@5.6.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index 102d8a316f9f4..6fe2e7fd9841a 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -92,6 +92,7 @@ def install end def post_install + # TODO add same as in mysql5.7 formula # Make sure the datadir exists datadir.mkpath unless (datadir/"mysql/general_log.CSM").exist? From f5c2c71494029b9b122cc22124d5e006118bee82 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Fri, 28 Aug 2020 19:51:42 +0100 Subject: [PATCH 04/15] Move pseudocode to comments and flesh out some working code. --- Formula/mysql@5.7.rb | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index aa7a08cdbcc8f..1566888957a0d 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -1,3 +1,11 @@ +# Altering to something like this: +# if datadir_is_already_mysql5.7 +# do_nothing +# elsif datadir_is_mysql8 +# choose_mysql5.7_specific_datadir +# elsif there_is_no_datadir +# choose_mysql5.7_specific_datadir +# end class MysqlAT57 < Formula desc "Open source relational database management system" homepage "https://dev.mysql.com/doc/refman/5.7/en/" @@ -28,7 +36,15 @@ class MysqlAT57 < Formula end def datadir - var/"mysql" + if datadir_is_mysql8? + var/"mysql57" + else + var/"mysql" + end + end + + def datadir_is_mysql8? + var.glob("mysql/*.dblwr").any? end def install @@ -86,16 +102,8 @@ def install end def post_install - if datadir_is_already_mysql5.7 - do_nothing - elsif datadir_is_mysql8 - choose_mysql5.7_specific_datadir - elsif there_is_no_datadir - choose_mysql5.7_specific_datadir - end - # Make sure the datadir exists - datadir.mkpath + datadir.mkpath #TODO check this wont cause any issues unless (datadir/"mysql/general_log.CSM").exist? ENV["TMPDIR"] = nil system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}", @@ -113,13 +121,6 @@ def caveats To connect run: mysql -uroot EOS - if datadir == (var/"mysql") && datadir.exist? - s += <<~EOS - - #{datadir} from another install may interfere with a Homebrew-built - server starting up correctly. - EOS - end if (my_cnf = ["/etc/my.cnf", "/etc/mysql/my.cnf"].find { |x| File.exist? x }) s += <<~EOS From 943133edbc6e7acb004a020b33ee6d39ba918659 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Tue, 1 Sep 2020 20:18:32 +0100 Subject: [PATCH 05/15] Detect MySQL 5.6, refactor. Refine logic for detecting which version of MySQL the datadir corresponds to by refactoring and adding heuristic for detection of MySQL 5.6. --- Formula/mysql@5.7.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index 1566888957a0d..71dce770d031b 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -36,15 +36,13 @@ class MysqlAT57 < Formula end def datadir - if datadir_is_mysql8? - var/"mysql57" - else - var/"mysql" - end + return var/"mysql" if default_datadir_already_in_use_by_this_version? + + var/"mysql57" end - def datadir_is_mysql8? - var.glob("mysql/*.dblwr").any? + def default_datadir_already_in_use_by_this_version? + var.glob("mysql/*.dblwr").empty? && !(var/"mysql/test").exist? && (var/"mysql").exist? end def install From a5ce548014b5a140f6020f042864160062b84200 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Sun, 6 Sep 2020 11:37:07 +0100 Subject: [PATCH 06/15] Fix style issues. --- Formula/mysql@5.6.rb | 2 +- Formula/mysql@5.7.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index 6fe2e7fd9841a..fc40e13823021 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -92,7 +92,7 @@ def install end def post_install - # TODO add same as in mysql5.7 formula + # TODO: add same as in mysql5.7 formula # Make sure the datadir exists datadir.mkpath unless (datadir/"mysql/general_log.CSM").exist? diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index 71dce770d031b..6b3c91566cc93 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -101,7 +101,7 @@ def install def post_install # Make sure the datadir exists - datadir.mkpath #TODO check this wont cause any issues + datadir.mkpath # TODO: check this wont cause any issues unless (datadir/"mysql/general_log.CSM").exist? ENV["TMPDIR"] = nil system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}", From 6992d7a58eeccf55596fcd0e7222f52ad6c107d0 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Sun, 6 Sep 2020 13:02:21 +0100 Subject: [PATCH 07/15] MySQL 5.6 formula installation directory. Use special installation directory in MySQL 5.6 formula as well, unless the default is already being used. --- Formula/mysql@5.6.rb | 9 +++++++-- Formula/mysql@5.7.rb | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index fc40e13823021..1582c0ab0db22 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -22,7 +22,13 @@ class MysqlAT56 < Formula depends_on "openssl@1.1" def datadir - var/"mysql" + return var/"mysql" if default_datadir_already_in_use_by_this_version? + + var/"mysql56" + end + + def default_datadir_already_in_use_by_this_version? + (var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && (var/"mysql/test").exist? end def install @@ -92,7 +98,6 @@ def install end def post_install - # TODO: add same as in mysql5.7 formula # Make sure the datadir exists datadir.mkpath unless (datadir/"mysql/general_log.CSM").exist? diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index 6b3c91566cc93..27796160f1a84 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -42,7 +42,7 @@ def datadir end def default_datadir_already_in_use_by_this_version? - var.glob("mysql/*.dblwr").empty? && !(var/"mysql/test").exist? && (var/"mysql").exist? + (var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && !(var/"mysql/test").exist? end def install @@ -101,7 +101,7 @@ def install def post_install # Make sure the datadir exists - datadir.mkpath # TODO: check this wont cause any issues + datadir.mkpath unless (datadir/"mysql/general_log.CSM").exist? ENV["TMPDIR"] = nil system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}", From ab78b97d0f6842a2de745113c9f3d992d09872ef Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Sun, 6 Sep 2020 13:06:31 +0100 Subject: [PATCH 08/15] Remove pseudocode. --- Formula/mysql@5.7.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index 27796160f1a84..ad1651b5010f5 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -1,11 +1,3 @@ -# Altering to something like this: -# if datadir_is_already_mysql5.7 -# do_nothing -# elsif datadir_is_mysql8 -# choose_mysql5.7_specific_datadir -# elsif there_is_no_datadir -# choose_mysql5.7_specific_datadir -# end class MysqlAT57 < Formula desc "Open source relational database management system" homepage "https://dev.mysql.com/doc/refman/5.7/en/" From 17eb9456f97ed89248da26719284d2de01bf0051 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Sun, 6 Sep 2020 19:36:39 +0100 Subject: [PATCH 09/15] Add note about removing mysqlbug --- Formula/mysql@5.6.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index 1582c0ab0db22..e00d3d0120bce 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -68,6 +68,11 @@ def install system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}" end + # TODO: Avoid references to the Homebrew shims directory or remove + # mysqlbug binary as it's deprecated in this version anyway + # maybe something like: inreplace bin/"mysqlbug", "a", "b" + # or simply deleting mysqlbug from the built files. + # Remove the tests directory rm_rf prefix/"mysql-test" From ee744afcc64e4a72a9b9c1446428b12a3fc01653 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Sun, 6 Sep 2020 21:34:57 +0100 Subject: [PATCH 10/15] Remove deprecated mysqlbug utility as it contains shims. --- Formula/mysql@5.6.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index e00d3d0120bce..8f62709ed5d03 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -68,10 +68,8 @@ def install system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}" end - # TODO: Avoid references to the Homebrew shims directory or remove - # mysqlbug binary as it's deprecated in this version anyway - # maybe something like: inreplace bin/"mysqlbug", "a", "b" - # or simply deleting mysqlbug from the built files. + # Remove deprecated bug reporting tool + rm prefix/"bin/mysqlbug" # Remove the tests directory rm_rf prefix/"mysql-test" From 56d318bc7946cbb624eebbadad88490aa5963adc Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Mon, 7 Sep 2020 21:51:50 +0100 Subject: [PATCH 11/15] Use tmpdir for socket in test. Specify socket location in tmpdir to avoid conflicting with running MySQL instances during test. --- Formula/mysql@5.7.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index ad1651b5010f5..d581e8c6333f1 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -155,7 +155,8 @@ def plist port = free_port pid = fork do - exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}", "--port=#{port}" + exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}", "--port=#{port}", + "--socket=#{dir}/mysql.sock}" end sleep 2 From 93b8b077f3a59dcb18ccd1cb5bdc255b47e044d5 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Tue, 8 Sep 2020 20:46:25 +0100 Subject: [PATCH 12/15] Add notes on another ways of checking which the mysql version. --- Formula/mysql@5.6.rb | 6 ++++++ Formula/mysql@5.7.rb | 1 + 2 files changed, 7 insertions(+) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index 8f62709ed5d03..06aded6141045 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -27,6 +27,12 @@ def datadir var/"mysql56" end + # TODO: Could also try running file on files in var/*.frm if they exist + # e.g. + # peter@Peters-iMac homebrew-core % file /usr/local/var/mysql56/mysql/columns_priv.frm + # /usr/local/var/mysql56/mysql/columns_priv.frm: MySQL table definition file Version 9, + # type MYISAM, MySQL version 50647 + # def default_datadir_already_in_use_by_this_version? (var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && (var/"mysql/test").exist? end diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index d581e8c6333f1..d95d11db768dd 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -33,6 +33,7 @@ def datadir var/"mysql57" end + # TODO: Could also try running file on files in var/*.frm if they exist def default_datadir_already_in_use_by_this_version? (var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && !(var/"mysql/test").exist? end From e6936de8f5cf309cf7dfea0a050ef1bbadf3fd61 Mon Sep 17 00:00:00 2001 From: Peter Baker Date: Wed, 9 Sep 2020 18:46:20 +0100 Subject: [PATCH 13/15] Update Formula/mysql@5.7.rb Co-authored-by: Mike McQuaid --- Formula/mysql@5.7.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index d95d11db768dd..3d01fb747f88b 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -157,7 +157,7 @@ def plist port = free_port pid = fork do exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}", "--port=#{port}", - "--socket=#{dir}/mysql.sock}" + "--socket=#{dir}/mysql.sock" end sleep 2 From 2dd4960b00efada6cfee973944b1444ee04aa97f Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Wed, 9 Sep 2020 20:20:53 +0100 Subject: [PATCH 14/15] Simply legacy mysql formulae by specifying a separate data directory for each version. --- Formula/mysql@5.6.rb | 15 +++------------ Formula/mysql@5.7.rb | 10 +++------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Formula/mysql@5.6.rb b/Formula/mysql@5.6.rb index 06aded6141045..3f4c370df026b 100644 --- a/Formula/mysql@5.6.rb +++ b/Formula/mysql@5.6.rb @@ -22,21 +22,9 @@ class MysqlAT56 < Formula depends_on "openssl@1.1" def datadir - return var/"mysql" if default_datadir_already_in_use_by_this_version? - var/"mysql56" end - # TODO: Could also try running file on files in var/*.frm if they exist - # e.g. - # peter@Peters-iMac homebrew-core % file /usr/local/var/mysql56/mysql/columns_priv.frm - # /usr/local/var/mysql56/mysql/columns_priv.frm: MySQL table definition file Version 9, - # type MYISAM, MySQL version 50647 - # - def default_datadir_already_in_use_by_this_version? - (var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && (var/"mysql/test").exist? - end - def install # Don't hard-code the libtool path. See: # https://github.com/Homebrew/homebrew/issues/20185 @@ -121,6 +109,9 @@ def caveats A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. + To avoid conflicts with other versions, the data directory location has been + set to mysql56. + MySQL is configured to only allow connections from localhost by default To connect: diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index d95d11db768dd..c3108cc682087 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -28,16 +28,9 @@ class MysqlAT57 < Formula end def datadir - return var/"mysql" if default_datadir_already_in_use_by_this_version? - var/"mysql57" end - # TODO: Could also try running file on files in var/*.frm if they exist - def default_datadir_already_in_use_by_this_version? - (var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && !(var/"mysql/test").exist? - end - def install # -DINSTALL_* are relative to `CMAKE_INSTALL_PREFIX` (`prefix`) args = %W[ @@ -107,6 +100,9 @@ def caveats We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation + To avoid conflicts with other versions, the data directory location has been + set to mysql57. + MySQL is configured to only allow connections from localhost by default To connect run: From d61101d76e08e2152678a04a2c68705444393369 Mon Sep 17 00:00:00 2001 From: Peter de Chair Baker Date: Fri, 11 Sep 2020 13:41:20 +0100 Subject: [PATCH 15/15] Remove custom socket as it appears that the CI error is unrelated. --- Formula/mysql@5.7.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Formula/mysql@5.7.rb b/Formula/mysql@5.7.rb index 6ac50c064b7ca..1fd541f876f88 100644 --- a/Formula/mysql@5.7.rb +++ b/Formula/mysql@5.7.rb @@ -152,8 +152,7 @@ def plist port = free_port pid = fork do - exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}", "--port=#{port}", - "--socket=#{dir}/mysql.sock" + exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}", "--port=#{port}" end sleep 2