#!/bin/bash
#Date:2017-04-23
#Author:Allen_Jol
#mariadb_install_v1.0.sh
#Version:mariadb-10.1.22
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比克山網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式克山網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋克山地區(qū)。費用合理售后完善,十年實體公司更值得信賴。
MARIADB_VERSION="mariadb-10.1.22.tar.gz"
echo "mariadb版本是:$MARIADB_VERSION"
PATHWAY=/usr/local/src
cd $PATHWAY
echo "====================PREPARE======================"
echo "原來裝過的或者自帶的MySQL如下:"
rpm -qa | grep mysql
#如果是centos7.2默認安裝了mariadb-libs,要先卸載
#rpm -e --nodeps mariadb-libs
sleep 3
#rm -rf /etc/my.cnf
yum -y remove mysql*
ls *.tar.gz | xargs -n1 tar zxvf
sleep 5
yum -y install libevent 'Development Tools' ncurses-devel openssl-devel openssl gcc gcc-c++ cmake make
sleep 3
groupadd mysql
useradd -r -g mysql mysql -s /sbin/nologin
mkdir -p /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/data
sleep 3
#編譯安裝開始
echo "==============mariadb install will be start for 3 seconds later========"
sleep 3
if [ ! -f mariadb-10.1.22.tar.gz ]
then
echo "沒有$MARIADB_VERSION這個包,請查看!"
sleep 3
exit 1
else
tar -zxvf $MARIADB_VERSION
cd ${MARIADB_VERSION%.tar.gz}
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
fi
sleep 3
echo $?
sleep 3
#-j 2代表用cpu雙線程去make,這樣速度快。lscpu可以查看cpu(s)是多少。
#make -j $(grep processor /proc/cpuinfo | wc –l)
#-j 參數(shù)表示根據(jù) CPU 核數(shù)指定編譯時的線程數(shù),可以加快編譯速度。默認為 1 個線程編譯
#一個processor就是一個線程
make -j 4
sleep 1
make install
echo $?
chown -R mysql:mysql /usr/local/mysql/data/
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
sleep 3
\cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
\cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
chkconfig --add mysql
chkconfig mysql on
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
/etc/init.d/mysql start
ps -ef | grep mysql
echo "記得登錄數(shù)據(jù)庫更改數(shù)據(jù)庫密碼,刷新權限。"
echo "如果不能直接用mysql登錄數(shù)據(jù)庫,請手動source /etc/profile一下"
echo "=================Mariadb installed successfully!===Congratulation==="