#!/bin/bash
rpm -qa |grep mariadb |xargs -i rpm -e {} --nodeps
filepath=/tools/
file=mariadb-5.5.56-linux-x86_64.tar.gz
mkdir -p /data/mysql_data
useradd -s /sbin/nologin mysql
tar -zxf $filepath$file -C /usr/local
arr=$(echo $file | awk -F '.tar' {'print $1'})
mv /usr/local/${arr[0]} /usr/local/mysql
yes |cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
sed -i '0,/datadir/{/datadir/d}' /etc/my.cnf && sed -i '/^\[mysqld\]/a\datadir = /data/mysql_data\nlog-warning=2' /etc/my.cnf
cd /usr/local/mysql/ && ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql_data
mkdir /var/log/mariadb/ && chown mysql.mysql /var/log/mariadb/
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
echo "export PATH=/usr/local/mysql/bin:\$PATH" >> /etc/profile
source /etc/profile
chkconfig --add mysqld