-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
mysql.rb
179 lines (154 loc) · 5.37 KB
/
mysql.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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.21.tar.gz"
sha256 "37231a123372a95f409857364dc1deb196b6f2c0b1fe60cc8382c7686b487f11"
license "GPL-2.0"
revision 1
livecheck do
url "https://dev.mysql.com/downloads/mysql/"
regex(/href=.*?mysql[._-]v?(\d+.\d+.\d+)-/i)
end
bottle do
sha256 "81e92d0df39edaff415e7d52f8d24db15db4469e99a7fbc915c92671a77e1374" => :catalina
sha256 "2383f7243ac47f28be988c66253251d8a71b51c1583d3550e6a9e1ab2931e951" => :mojave
sha256 "92bde22c4e13a0c888e7b7b9e62003e227a72a331c13a35cac98d9e7936ae387" => :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
depends_on "[email protected]"
depends_on "protobuf"
uses_from_macos "libedit"
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
-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=#{Formula["[email protected]"].opt_prefix}
-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 libssl copies as the binaries use the keg anyway and they create problems for other applications
rm_rf lib/"libssl.dylib"
rm_rf lib/"libssl.1.1.dylib"
rm_rf lib/"libcrypto.1.1.dylib"
rm_rf lib/"libcrypto.dylib"
rm_rf lib/"plugin/libcrypto.1.1.dylib"
rm_rf lib/"plugin/libssl.1.1.dylib"
# 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}"
port = free_port
pid = fork do
exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}", "--port=#{port}"
end
sleep 2
output = shell_output("curl 127.0.0.1:#{port}")
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