Skip to content

Instantly share code, notes, and snippets.

@etipton
Last active August 4, 2016 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etipton/8dead5a3397f6bd7edb2 to your computer and use it in GitHub Desktop.
Save etipton/8dead5a3397f6bd7edb2 to your computer and use it in GitHub Desktop.
Specify settings in mysql launchctl plist file
#!/usr/bin/env ruby
plist_file = File.expand_path('~/Library/LaunchAgents/homebrew.mxcl.mysql.plist')
File.open(plist_file, 'r+') do |f|
contents = f.read
args_end = ' </array>' # this is kinda brittle, but whatever
charset_opt = ' <string>--character-set-server=latin1</string>'
collate_opt = ' <string>--collation-server=latin1_swedish_ci</string>'
sql_mode_opt = ' <string>--sql-mode=NO_ENGINE_SUBSTITUTION</string>'
contents.sub!(args_end, [charset_opt, args_end].join("\n")) unless contents.include?('character-set-server')
contents.sub!(args_end, [collate_opt, args_end].join("\n")) unless contents.include?('collation-server')
contents.sub!(args_end, [sql_mode_opt, args_end].join("\n")) unless contents.include?('sql-mode')
f.rewind
f.write(contents)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment