Skip to content

Instantly share code, notes, and snippets.

@Ameen-Alam
Forked from mansurali901/setup_mysql5.7_source.sh
Created September 22, 2020 00:04
Show Gist options
  • Save Ameen-Alam/5b1695bd6bbe95254ec77f91b7f95f3d to your computer and use it in GitHub Desktop.
Save Ameen-Alam/5b1695bd6bbe95254ec77f91b7f95f3d to your computer and use it in GitHub Desktop.
Setup Mysql 5.7 from Source Code
#!/bin/bash
# This script used to install Mysql 5.7
# from source Code
# Author Mansur Ul Hasan
# mansurali901@gmail.com
# Environment Function
PrepBuildEnvFunc () {
echo "Installing Required packages for MySql"
apt-get update -y
apt-get install libreadline6-dev libncurses5-dev build-essential cmake make wget unzip zip -y
## Some Additional Packages
apt-get install libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl -y
}
## Building Operating System
PrepApp () {
#s Add Users and Group
usergroup mysql
useradd -r -U mysql -M -d /var/lib/mysql
}
PreSrc () {
echo "Downloading Source Code"
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21.zip
unzip mysql-5.7.21.zip
echo "
===============================================================
| Mysql Installation Script
| Note : This will take long in building and compiling
| Ensure that you have backup power.
==============================================================="
# Boost is platform used by CMAKE to build Framework
cd /root/mysql-5.7.21/
mkdir /usr/local/boost_1_59_0/
cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost_1_59_0/
### Creating platform for MySql Installation with CMAKE and BOOST
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/src/mysql-5.7.21 \
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/etc \
.
# After buiding platform Framwork we need to install
# Binaries using the CMAKE & Boost
make
make install
}
PostInstProc () {
# Post Installation process started
# Creating Required directories
# Copying configuration files to
# desired locations.
ln -s /usr/local/src/mysql-5.7.21 /usr/local/mysql
cd /usr/local/mysql
# Updating Mysql Configuration File.
wget https://gist.githubusercontent.com/mansurali901/d4f6d63439d5be3d60ec53d032cec8e1/raw/86a6ec4d260a76ef8264f50f1e1d3be2cb3384ad/my.cnf
cp my.cnf /etc/my.cnf
echo "character-set-server = utf8" >> /etc/my.cnf
echo "collation-server = utf8_general_ci" >> /etc/my.cnf
echo "character-set-client-handshake = false" >> /etc/my.cnf
# Updating Data directory and PID path Location
sed -i 's/datadir=data/datadir=\/usr\/local\/mysql\/data/g' /etc/my.cnf
sed -i 's/\/var\/run\/mysqld\/mysqld.pid/\/tmp\/mysqld.pid/g' /etc/my.cnf
touch /var/log/mysqld.log ; chown root:mysql /var/log/mysqld.log ;chmod g+w /var/log/mysqld.log
# Data Directory location creation and Permission Setup
mkdir /usr/local/mysql/data
chown -R root:mysql /usr/local/mysql
cd /usr/local/mysql;chown -R root:mysql data/
# Initializing Mysql for first time
echo "
#########################################
Mysql going to initialize please note that
this will generate a temporary password
which can be used to login first time after
Successful login first change password.
#########################################
"
/usr/local/mysql/bin/mysqld --initialize
tail -f /var/log/mysqld.log
echo "Mysql has been installled please use temp password.."
# Copying Serice files.
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
ln -s /etc/init.d/mysql.server /etc/rc2.d/S90mysql
# Exporting Environmental variable
echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
# Starting MySql
/usr/local/src/mysql-5.7.21/bin/mysqld --user=mysql &
}
MainFunc () {
# Calling all Functions
PrepBuildEnvFunc
PrepApp
PreSrc
PostInstProc
}
MainFunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment