Sha256: f4f467cb6bb0b578f16f6e37d5219c1cb3a1b2e20ceab55d496bb54747d0116c

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

module BinInstall
  module Mysql
    def self.install(version = nil)
      puts 'Installing MySQL...'.white
      if version
        Brew::Package.install_or_upgrade("mysql@#{version}")
      else
        Brew::Package.install_or_upgrade('mysql')
      end
      Brew::Service.start('mysql')
      Shell.wait(10) # Give MySQL time to spin up.
    end

    def self.install!(version = nil)
      puts 'Installing MySQL...'.white
      if version
        Brew::Package.install_or_upgrade!("mysql@#{version}")
      else
        Brew::Package.install_or_upgrade!('mysql')
      end
      Brew::Service.start!('mysql')
      Shell.wait(10) # Give MySQL time to spin up.
    end

    def self.create_root
      puts 'Creating root user for MySQL....'.white
      system("mysqladmin --user=root password ''")
    end

    def self.create_root!
      puts 'Creating root user for MySQL....'.white
      BinInstall.system!("mysqladmin --user=root password ''")
    end

    def self.create_user(username, password = nil)
      puts "Creating user #{username} for MySQL...".white
      system(%(mysql --user=root --execute="CREATE USER '#{username}'@'localhost' IDENTIFIED BY '#{password}';"))
      system(%(mysql --user=root --execute="GRANT ALL PRIVILEGES ON *.* TO '#{username}'@'localhost' WITH GRANT OPTION;"))
    end

    def self.create_user!(username, password = nil)
      puts "Creating user #{username} for MySQL...".white
      BinInstall.system!(%(mysql --user=root --execute="CREATE USER '#{username}'@'localhost' IDENTIFIED BY '#{password}';"))
      BinInstall.system!(%(mysql --user=root --execute="GRANT ALL PRIVILEGES ON *.* TO '#{username}'@'localhost' WITH GRANT OPTION;"))
    end

    def self.installed?
      Shell.executable_exists?('mysql')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bin_install-0.0.33 lib/bin_install/mysql.rb
bin_install-0.0.32 lib/bin_install/mysql.rb