Skip to content

Instantly share code, notes, and snippets.

@hadashiA
Last active September 23, 2016 07:01
Show Gist options
  • Save hadashiA/4583936 to your computer and use it in GitHub Desktop.
Save hadashiA/4583936 to your computer and use it in GitHub Desktop.
require 'formula'
class Mysql41 < Formula
homepage 'http://download.softagency.net/MySQL/Downloads/MySQL-4.1/'
url 'http://download.softagency.net/MySQL/Downloads/MySQL-4.1/mysql-4.1.22.tar.gz'
version '4.1.22'
md5 '37b4479951fa0cf052269d27c41ca200'
depends_on 'readline'
# mysql.rb options:
# オプションは、build.include?(name) でON/OFFを参照できる。とりあえずコメントアウト
# option :universal
# option 'with-tests', 'Build with unit tests'
# option 'with-embedded', 'Build the embedded server'
# option 'with-libedit', 'Compile with editline wrapper instead of readline'
# option 'with-archive-storage-engine', 'Compile with the ARCHIVE storage engine enabled'
# option 'with-blackhole-storage-engine', 'Compile with the BLACKHOLE storage engine enabled'
# option 'enable-local-infile', 'Build with local infile loading support'
# option 'enable-debug', 'Build with debug support'
conflicts_with 'mysql',
:because => "install the same binaries."
conflicts_with 'mariadb',
:because => "mysql and mariadb install the same binaries."
conflicts_with 'percona-server',
:because => "mysql and percona-server install the same binaries."
conflicts_with 'mysql-cluster',
:because => "mysql and mysql-cluster install the same binaries."
def install
# Build without compiler or CPU specific optimization flags to facilitate
# compilation of gems and other software that queries `mysql-config`.
# ENV.minimal_optimization
# Make sure the var/mysql directory exists
(var+"mysql").mkpath
system "./configure", "--prefix=#{prefix}",
"--with-charset=utf8", "--with-collation=utf8_general_ci",
"--sysconfdir=#{etc}", "--datadir=#{var}/mysql", "--localstatedir=#{var}/mysql",
"--mandir=#{man}", "--infodir=#{info}",
"--without-readline", "--without-libedit"
system "make"
system "make install"
# ln_s prefix+'scripts/mysql_install_db', bin+'mysql_install_db'
system "cp -r ./support-files #{prefix}/support-files"
system "chmod +x #{prefix}/support-files/mysql.server"
# Fix up the control script and link into bin
inreplace "#{prefix}/support-files/mysql.server" do |s|
s.gsub!(/^(PATH=".*)(")/, "\\1:#{HOMEBREW_PREFIX}/bin\\2")
# pidof can be replaced with pgrep from proctools on Mountain Lion
s.gsub!(/pidof/, 'pgrep') if MacOS.version >= :mountain_lion
end
ln_s "#{prefix}/support-files/mysql.server", bin
end
def caveats; <<-EOS.undent
Set up databases to run AS YOUR USER ACCOUNT with:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql41)" --datadir=#{var}/mysql --tmpdir=/tmp
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysqld_install_db:
mysql_install_db --help
and view the MySQL documentation:
* http://dev.mysql.com/doc/refman/4.1/ja/mysql-install-db.html
* http://dev.mysql.com/doc/refman/4.1/ja/default-privileges.html
To run as, for instance, user "mysql", you may need to `sudo`:
sudo mysql_install_db ...options...
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To connect:
mysql -uroot
EOS
end
plist_options :manual => "mysql.server start"
def plist; <<-EOS.undent
<?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>Program</key>
<string>#{opt_prefix}/bin/mysqld_safe</string>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>#{`whoami`.chomp}</string>
<key>WorkingDirectory</key>
<string>#{var}</string>
</dict>
</plist>
EOS
end
end
# brew install ./mysql41.rb --use-gcc
# mysql_install_db --verbose --user=`whoami` --basedir="/usr/local/opt/mysql41" --datadir=/usr/local/var/mysql --tmpdir=/tmp
# mysql.server start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment