Last active
October 22, 2016 16:15
-
-
Save alastori/929beb23f583bde24c2318cffbdb75b2 to your computer and use it in GitHub Desktop.
Bash script to provision MySQL 5.7 Community via local RPMs in Enterprise Linux 7.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Bash script to provision MySQL 5.7 Community via local RPMs in Enterprise Linux 7.x | |
#Copy the TAR with mysql* RPMs into the $PACKAGES_DIR and run this script as root | |
#You can find the community binaries in http://dev.mysql.com/downloads | |
#Modify these variables as you wish | |
DIR_TO_UNPACK=/tmp/packages | |
PACKAGES_DIR=/home/vagrant/packages #This folder already contains RPMs | |
MYSQL_PWD="Root#123" | |
TAR_BUNDLE=mysql-5.7*rpm-bundle.tar # normally community is mysql-5.7.*.el7.x86_64.rpm-bundle.tar | |
REMOTE_USER=remote | |
REMOTE_PWD="Remote#123" | |
set -e # stop script execution on any error | |
#Next lines install MySQL Server from RPM file | |
echo "Looking for RMPs in TAR Bundle $PACKAGES_DIR/$TAR_BUNDLE..." | |
ls $PACKAGES_DIR/$TAR_BUNDLE | |
echo "Unpacking TAR to $DIR_TO_UNPACK..." | |
mkdir -p $DIR_TO_UNPACK | |
cd $DIR_TO_UNPACK | |
tar xvf $PACKAGES_DIR/$TAR_BUNDLE -C $DIR_TO_UNPACK | |
yum -y localinstall mysql*{server,client,common,libs,libs-compat}-5.7*.rpm | |
echo "MySQL installed via RPM from $DIR_TO_UNPACK" | |
#Starting MySQL Server | |
echo "Starting MySQL for the first time..." | |
service mysqld start | |
sleep 8 | |
service mysqld status | |
echo "Changing temporary password..." | |
MYSQL_TMP_PWD="$(echo "$a" | cat /var/log/mysqld.log | grep "A temporary password is generated for root@localhost: " | sed "s|^.*localhost: ||")" | |
echo $MYSQL_TMP_PWD $MYSQL_PWD | |
mysqladmin -uroot -p"$MYSQL_TMP_PWD" password "$MYSQL_PWD" | |
mysql -uroot -p"$MYSQL_PWD" -e"SELECT @@hostname,@@port,@@version;" | |
#Creating 'remote' user | |
mysql -uroot -p$MYSQL_PWD -e" \ | |
CREATE USER ""'"$REMOTE_USER"'""@'%' IDENTIFIED BY ""'"$REMOTE_PWD"'""; \ | |
GRANT ALL PRIVILEGES ON *.* TO ""'"$REMOTE_USER"'""@'%' WITH GRANT OPTION; " | |
mysql -u$REMOTE_USER -p"$REMOTE_PWD" -e"SELECT USER(), CURRENT_USER();" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment