169 lines
5.1 KiB
Ruby
169 lines
5.1 KiB
Ruby
class Mysql < Formula
|
|
desc "Open source relational database management system"
|
|
homepage "https://dev.mysql.com/doc/refman/8.0/en/"
|
|
url "https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-8.0.19.tar.gz"
|
|
sha256 "3622d2a53236ed9ca62de0616a7e80fd477a9a3f862ba09d503da188f53ca523"
|
|
|
|
bottle do
|
|
sha256 "2754abf3fefc4128b5aba75966ce68aebce156c718567908f8eaa2611251f951" => :catalina
|
|
sha256 "4b18d45af8dcd0d1fea0e7c82a7ed8a6ce3a0bb9e5be6bf4d395460126a0ac70" => :mojave
|
|
sha256 "eaf32cf0e17c95d195372b9014852dc77e423dfa8b2362566703edb85449458a" => :high_sierra
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
|
|
# GCC is not supported either, so exclude for El Capitan.
|
|
depends_on :macos => :sierra if DevelopmentTools.clang_build_version == 800
|
|
|
|
# https://github.com/Homebrew/homebrew-core/issues/1475
|
|
# Needs at least Clang 3.6, which shipped alongside Yosemite.
|
|
# Note: MySQL themselves don't support anything below Sierra.
|
|
depends_on :macos => :yosemite
|
|
|
|
depends_on "openssl@1.1"
|
|
depends_on "protobuf"
|
|
|
|
conflicts_with "mariadb", "percona-server",
|
|
:because => "mysql, mariadb, and percona install the same binaries."
|
|
|
|
# https://bugs.mysql.com/bug.php?id=86711
|
|
# https://github.com/Homebrew/homebrew-core/pull/20538
|
|
fails_with :clang do
|
|
build 800
|
|
cause "Wrong inlining with Clang 8.0, see MySQL Bug #86711"
|
|
end
|
|
|
|
def datadir
|
|
var/"mysql"
|
|
end
|
|
|
|
def install
|
|
# -DINSTALL_* are relative to `CMAKE_INSTALL_PREFIX` (`prefix`)
|
|
args = %W[
|
|
-DFORCE_INSOURCE_BUILD=1
|
|
-DCOMPILATION_COMMENT=Homebrew
|
|
-DDEFAULT_CHARSET=utf8mb4
|
|
-DDEFAULT_COLLATION=utf8mb4_general_ci
|
|
-DINSTALL_DOCDIR=share/doc/#{name}
|
|
-DINSTALL_INCLUDEDIR=include/mysql
|
|
-DINSTALL_INFODIR=share/info
|
|
-DINSTALL_MANDIR=share/man
|
|
-DINSTALL_MYSQLSHAREDIR=share/mysql
|
|
-DINSTALL_PLUGINDIR=lib/plugin
|
|
-DMYSQL_DATADIR=#{datadir}
|
|
-DSYSCONFDIR=#{etc}
|
|
-DWITH_BOOST=boost
|
|
-DWITH_EDITLINE=system
|
|
-DWITH_SSL=yes
|
|
-DWITH_PROTOBUF=system
|
|
-DWITH_UNIT_TESTS=OFF
|
|
-DENABLED_LOCAL_INFILE=1
|
|
-DWITH_INNODB_MEMCACHED=ON
|
|
]
|
|
|
|
system "cmake", ".", *std_cmake_args, *args
|
|
system "make"
|
|
system "make", "install"
|
|
|
|
(prefix/"mysql-test").cd do
|
|
system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}"
|
|
end
|
|
|
|
# Remove the tests directory
|
|
rm_rf prefix/"mysql-test"
|
|
|
|
# Don't create databases inside of the prefix!
|
|
# See: https://github.com/Homebrew/homebrew/issues/4975
|
|
rm_rf prefix/"data"
|
|
|
|
# Fix up the control script and link into bin.
|
|
inreplace "#{prefix}/support-files/mysql.server",
|
|
/^(PATH=".*)(")/,
|
|
"\\1:#{HOMEBREW_PREFIX}/bin\\2"
|
|
bin.install_symlink prefix/"support-files/mysql.server"
|
|
|
|
# Install my.cnf that binds to 127.0.0.1 by default
|
|
(buildpath/"my.cnf").write <<~EOS
|
|
# Default Homebrew MySQL server config
|
|
[mysqld]
|
|
# Only allow connections from localhost
|
|
bind-address = 127.0.0.1
|
|
mysqlx-bind-address = 127.0.0.1
|
|
EOS
|
|
etc.install "my.cnf"
|
|
end
|
|
|
|
def post_install
|
|
# Make sure the datadir exists
|
|
datadir.mkpath
|
|
unless (datadir/"mysql/general_log.CSM").exist?
|
|
ENV["TMPDIR"] = nil
|
|
system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{datadir}", "--tmpdir=/tmp"
|
|
end
|
|
end
|
|
|
|
def caveats
|
|
s = <<~EOS
|
|
We've installed your MySQL database without a root password. To secure it run:
|
|
mysql_secure_installation
|
|
|
|
MySQL is configured to only allow connections from localhost by default
|
|
|
|
To connect run:
|
|
mysql -uroot
|
|
EOS
|
|
if my_cnf = ["/etc/my.cnf", "/etc/mysql/my.cnf"].find { |x| File.exist? x }
|
|
s += <<~EOS
|
|
|
|
A "#{my_cnf}" from another install may interfere with a Homebrew-built
|
|
server starting up correctly.
|
|
EOS
|
|
end
|
|
s
|
|
end
|
|
|
|
plist_options :manual => "mysql.server start"
|
|
|
|
def plist; <<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>KeepAlive</key>
|
|
<true/>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_bin}/mysqld_safe</string>
|
|
<string>--datadir=#{datadir}</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>WorkingDirectory</key>
|
|
<string>#{datadir}</string>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
# Expects datadir to be a completely clean dir, which testpath isn't.
|
|
dir = Dir.mktmpdir
|
|
system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{dir}", "--tmpdir=#{dir}"
|
|
|
|
pid = fork do
|
|
exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}"
|
|
end
|
|
sleep 2
|
|
|
|
output = shell_output("curl 127.0.0.1:3306")
|
|
output.force_encoding("ASCII-8BIT") if output.respond_to?(:force_encoding)
|
|
assert_match version.to_s, output
|
|
ensure
|
|
Process.kill(9, pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|