标签:自动安装mysql
#!/bin/bash
############################################
# automatic configure mysql from source code since mysql 5.5.37 #
# edit by rgf in 2014/08/20 #
# e-mail gfsunny@163.com #
############################################
base_dir=/usr/local/mysql
data_root=/opt
data_dir=/opt/mysql/data
logs_dir=/opt/mysql/logs
db_user=root
db_pwd=123456
db_version=mysql-5.5.37
echo
echo "No.1: create group && user for mysql"
echo
grep mysql /etc/group &> /dev/null
if [ $? == 0 ]; then
echo "group: mysql already exists"
else
groupadd mysql
fi
grep mysql /etc/passwd &> /dev/null
if [ $? == 0 ]; then
echo "user: mysql already exists"
else
useradd -g mysql mysql
fi
echo "check relative user and group done! "
echo
echo "No.2:define and create relative directory"
if [ ! -d "$base_dir" ];then
mkdir -p "$base_dir"
echo ""$base_dir" has been created"
else
echo ""$base_dir" directory already exists"
fi
if [ ! -d "$data_dir" ];then
mkdir -p "$data_dir"
echo ""$data_dir" has been created"
else
echo ""$data_dir" directory already exists"
fi
if [ ! -d "$logs_dir" ];then
mkdir -p "$logs_dir"
echo ""$logs_dir" has been created"
else
echo ""$logs_dir" directory already exists"
fi
cd $data_root
chown -R mysql:mysql *
cd -
echo "check relative directory done!"
echo "No.3: check whether mysql is already installed?"
echo
for i in MySQL MySQL-server MySQL-test MySQL-bench MySQL-connector-java MySQL-connector-odbc MySQL-devel MySQL-shared MySQL-client MySQL-shared-compat
do
rpm -q $i &> /dev/null
if [ $? == 0 ]; then
rpm -e $i --nodeps &> /dev/null
echo "$i was uninstalled!!"
else
echo "$i had been uninstalled!!"
fi
done
echo
echo "No.4: check and install relative packages"
echo
rpm -qa |grep gcc &> /dev/null
if [ $? == 0 ]; then
echo "gcc already exists"
else
yum -y install gcc
fi
echo
rpm -qa |grep flex &> /dev/null
if [ $? == 0 ]; then
echo "flex already exists"
else
yum -y install flex
fi
echo
rpm -qa |grep bison &> /dev/null
if [ $? == 0 ]; then
echo "bison already exists"
else
yum -y install bison
fi
echo
echo
rpm -qa |grep autoconf &> /dev/null
if [ $? == 0 ]; then
echo "autoconf already exists"
else
yum -y install autoconf
fi
echo
echo
rpm -qa |grep automake &> /dev/null
if [ $? == 0 ]; then
echo "automake already exists"
else
yum -y install automake
fi
echo
echo
rpm -qa |grep cmake &> /dev/null
if [ $? == 0 ]; then
echo "cmake already exists"
else
yum -y install cmake
fi
echo
echo
rpm -qa |grep ncurses-devel &> /dev/null
if [ $? == 0 ]; then
echo "ncurses-devel already exists"
else
yum -y install ncurses-devel
fi
echo
echo
rpm -qa |grep curl-devel &> /dev/null
if [ $? == 0 ]; then
echo "curl-devel already exists"
else
yum -y install curl-devel
fi
echo
echo
rpm -qa |grep make &> /dev/null
if [ $? == 0 ]; then
echo "make already exists"
else
yum -y install make
fi
echo
echo
rpm -qa |grep lynx &> /dev/null
if [ $? == 0 ]; then
echo "lynx already exists"
else
yum -y install lynx
fi
echo "check relative install packages done! "
echo
echo "No.5: unzip $db_version"
echo
tar -zxvf "$db_version".tar.gz
cd "$db_version"
mkdir project
cd project
CFLAGS="-O3 -g -fno-exceptions -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
CXX=g++
CXXFLAGS="-O3 -g -fno-exceptions -fno-rtti -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
export CFLAGS CXX CXXFLAGS
sleep 2
cmake ..
-DCMAKE_INSTALL_PREFIX:PATH=$base_dir
-DMYSQL_DATADIR=$data_dir
-DSYSCONFDIR:PATH=/etc
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DCMAKE_BUILD_TYPE:STRING=Release
-DENABLE_PROFILING:BOOL=ON
-DWITH_DEBUG:BOOL=OFF
-DWITH_VALGRIND:BOOL=OFF
-DENABLE_DEBUG_SYNC:BOOL=OFF
-DWITH_EXTRA_CHARSETS:STRING=all
-DWITH_SSL:STRING=bundled
-DWITH_UNIT_TESTS:BOOL=OFF
-DWITH_ZLIB:STRING=bundled
-DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON
-DWITH_INNOBASE_STORAGE_ENGINE:BOOL=ON
-DWITH_ARCHIVE_STORAGE_ENGINE:BOOL=ON
-DWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON
-DWITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all
-DENABLED_LOCAL_INFILE:BOOL=ON
-DWITH_EMBEDDED_SERVER=0
-DINSTALL_LAYOUT:STRING=STANDALONE
-DCOMMUNITY_BUILD:BOOL=ON;
echo
echo "cmake compilation done! "
echo "No.6: make && make install"
make -j `cat /proc/cpuinfo | grep processor| wc -l`
make install
echo "mysql installation is over"
echo "No.7: Now,begin to change and set environment variables!!"
echo
cd $base_dir
chown -R mysql:mysql *
cd -
grep "$base_dir/bin" ~/.bashrc
if [ $? == 1 ];then
echo "export PATH=$PATH:$base_dir/bin" >> ~/.bashrc
else
echo "environment variables has setted"
fi
sleep 1
source ~/.bashrc
echo
echo "Now,to be going to install db"
$base_dir/scripts/mysql_install_db --user=mysql --datadir=$data_dir --basedir=$base_dir
alias cp=‘cp‘
cp -f $base_dir/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
echo "change and set environment variables done! "
echo
echo "No.8: Now,begin to start mysql server and test it!!"
echo
/etc/init.d/mysqld start
echo
mysqladmin -u$db_user password $db_pwd
mysqladmin -u$db_user -p$db_pwd create rgf
if [ $? == 0 ]; then
echo "mysql server is OK !"
else
echo "mysql server is wrong!"
fi
echo
mysqladmin -u$db_user -p$db_pwd -f drop rgf
echo "test is over and restart mysql! "
/etc/init.d/mysqld restart
ps -ef |grep -v grep |grep mysqld
if [ $? == 1 ];then
echo "please check mysql!"
else
echo "congratulation!!mysql is running!!"
fi
cd ../../
echo
echo "No.9: install mysql OK!!"
echo
#该脚本经过测试,运行正常。运用时只需要修改脚本开头的参数即可
标签:自动安装mysql
原文地址:http://gfsunny.blog.51cto.com/990565/1553594