Skip to content

Instantly share code, notes, and snippets.

@ariarijp
Last active September 20, 2016 13:49
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 ariarijp/fe2ac97f58240e881df2051a84e49dbb to your computer and use it in GitHub Desktop.
Save ariarijp/fe2ac97f58240e881df2051a84e49dbb to your computer and use it in GitHub Desktop.
SQL書き方ドリルのサンプルDBとMySQLのworldデータベースをre:dashで遊べるようにするVagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "redash/dev"
config.vm.synced_folder "./", "/opt/redash/current"
config.vm.network "forwarded_port", guest: 5000, host: 9001
config.vm.provision "shell" do |s|
s.inline = "/opt/redash/current/setup/vagrant/provision.sh"
s.privileged = false
end
config.vm.provision "shell", inline: <<-SHELL
# MySQLのインストール時にパスワード入力画面を表示しない
export DEBIAN_FRONTEND=noninteractive
# タイムゾーンを変更
echo "Asia/Tokyo" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# APTリポジトリーを日本のサーバーに変更
sed -i s/archive.ubuntu.com/jp.archive.ubuntu.com/ /etc/apt/sources.list
# MySQLと日本語言語パックをインストール
apt-get update
apt-get install -y mysql-server language-pack-ja
# MySQLのユーザーを作成
echo "CREATE USER 'redash'@'localhost' IDENTIFIED BY 'redash';" | mysql -uroot
# SQL書き方ドリルのサンプルデータが/vagrant/SQL_DRILLにある前提でテーブル作成、データインポート
if [ -e /vagrant/SQL_DRILL ]; then
echo "CREATE DATABASE sql_drill DEFAULT CHARSET utf8;" | mysql -uroot
echo "GRANT ALL PRIVILEGES ON sql_drill.* TO redash IDENTIFIED BY 'redash';" | mysql -uroot
cat /vagrant/SQL_DRILL/HTML_REFERENCE/sql/for_sample_db/create_for_mysql.sql | mysql -uredash -predash sql_drill
cat /vagrant/SQL_DRILL/HTML_REFERENCE/sql/for_sample_db/data.sql | mysql -uredash -predash sql_drill
fi
# worldのサンプルデータが/vagrant/world.sql.gzにある前提でデータインポート
if [ -e /vagrant/world.sql.gz ]; then
echo "GRANT ALL PRIVILEGES ON world.* TO redash IDENTIFIED BY 'redash';" | mysql -uroot
zcat /vagrant/world.sql.gz | mysql -uredash -predash
fi
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment