Skip to content

Commit

Permalink
Added MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojtek committed Mar 9, 2018
1 parent 512cad3 commit 175c0a5
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- PHP Error handling configuration
- *MySQL* server and database

### Changed
- Provisioning script to function based one (`src`) to improve flexibility
Expand Down
2 changes: 2 additions & 0 deletions bootstrap.sh
Expand Up @@ -21,4 +21,6 @@ base_setup

install_apache
install_composer
install_mysql
mysql_add_user user pass
install_tools
16 changes: 16 additions & 0 deletions conf/local.cnf
@@ -0,0 +1,16 @@
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8


[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
default-storage-engine=InnoDB
innodb_file_per_table=ON
innodb_file_format=barracuda
innodb_strict_mode=ON
innodb_buffer_pool_size = 256M
2 changes: 1 addition & 1 deletion src/apache.sh
Expand Up @@ -6,7 +6,7 @@ function install_apache()

#install apache2, PHP and then MySQL
apt-get -y install apache2
apt-get -y install php5 # php5-mcrypt php5-xdebug
apt-get -y install php5 php5-mysql # php5-mcrypt php5-xdebug

# Enable: ModRewrite, mcrypt
a2enmod rewrite
Expand Down
76 changes: 76 additions & 0 deletions src/mysql.sh
@@ -0,0 +1,76 @@
#!/bin/bash

function install_mysql()
{
header 'Installing MySQL'

if [ "$1" != "" ]
then
THE_PASSWORD="$1"
else
THE_PASSWORD="password"
fi

if [[ "$2" != "" ]]
then
DATABASE_NAME="$2"
else
DATABASE_NAME="develop"
fi

echo "mysql-server-5.5 mysql-server/root_password password "$THE_PASSWORD | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password "$THE_PASSWORD | debconf-set-selections

apt-get -y install mysql-server

# remove limits on network adapter
sed -i 's/bind-address/#bind-address/' /etc/mysql/my.cnf

# replace key_buffer with key_buffer_size. key_buffer is deprecated (http://kb.parallels.com/en/120461)
sed -i 's/key_buffer\s/key_buffer_size/' /etc/mysql/my.cnf

# add standard config.
cp /vagrant/conf/local.cnf /etc/mysql/conf.d/

sed -i 's/innodb_buffer_pool_size/#innodb_buffer_pool_size/' /etc/mysql/conf.d/local.cnf

# create database

header 'Creating Database: '$DATABASE_NAME

echo "CREATE DATABASE "$DATABASE_NAME | mysql -uroot -p$THE_PASSWORD

unset THE_PASSWORD
unset DATABASE_NAME

service mysql restart
}

function mysql_add_user()
{

header 'Adding MySQL user: '$1

if [ "$3" != "" ]
then
THE_PASSWORD="$3"
else
THE_PASSWORD="password"
fi

if [[ "$4" != "" ]]
then
DATABASE_NAME="$4"
else
DATABASE_NAME="develop"
fi

echo "CREATE USER '"$1"'@'%' IDENTIFIED BY '"$2"';" | mysql -uroot -p$THE_PASSWORD
echo "GRANT ALL PRIVILEGES ON "$DATABASE_NAME".* TO '"$1"'@'%' WITH GRANT OPTION;" | mysql -uroot -p$THE_PASSWORD

# flush privilages
echo "FLUSH PRIVILEGES;" | mysql -uroot -p$THE_PASSWORD

unset THE_PASSWORD
unset DATABASE_NAME
}

0 comments on commit 175c0a5

Please sign in to comment.