此文为mysql 服务器安装脚本。
#!/bin/bash
#ver 0.2
#by zm 2011/04/23
#安装 mysql_server;
#注意!!
#参数解释
#
# CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
# -fno-exceptions -fno-rtti -fomit-frame-pointer -ffixed-ebp" // 如果是Inter处理器,使用pgcc提高1%性能
#
#
# --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock // 使用unix套接字链接提高7.5%性能,所以在windows下mysql性能肯定不如unix下面
# --with-client-ldflags=-all-static
# --with-mysqld-ldflags=-all-static //-static 13%,静态链接提高13%性能
#
# --with-readline 从“行”上面读取
#
# --with-charset=utf8 指定缺省字符集
#
# --with-collation=utf8_general_ci 指定缺省排序方式
#
# --with-extra-charsets=complex 安装所有字符,有这个就足够了
#
# --with-extra-charsets=all 指定安装扩展字符集
#
# --enable-local-infile 指定允许本地导入文件
#
# --enable-thread-safe-client 指定线程安全模式
#
# --enable-assembler 允许使用汇编模式(优化性能)
#
# --with-big-tables 指定支持超大表
#
# --without-debug 去除诊断模式,如果用--with-debug=full编译,大多数查询慢20%
#
#变量
mysql_cnf_dir=/etc/my.cnf
mysql_dir=/usr/local/mysql
os_type=`uname`
user=`grep 'mysql' /etc/passwd | wc -l`
###mysql_server
#check os
if [ $os_type != "Linux" ];then
echo "the script for linux only!"
exit 1
fi
#check mysql user and group
if [ $user = 0 ];then
useradd -s /sbin/nologin mysql
echo "useradd mysql !"
fi
#
if [ ! -f "$mysql_cnf_dir" ] || [ ! -d "$mysql_dir" ];then
tar zxf mysql*.tar.gz
cd mysql*/
#
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -ffixed-ebp" \
./configure --prefix=/usr/local/mysql --enable-assembler \
--with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
--with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all \
--with-readline --enable-local-infile --enable-thread-safe-client \
--with-big-tables --without-debug
make
make install
#configure file
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
cd ../
rm -rf mysql*/
#install_mysql_db
mysql_var=`ls -l $mysql_dir/var/mysql | grep '^d' | wc -l`
if [ "$mysql_var" = 0 ];then
chow -R mysql.mysql $mysql_dir/var
chow -R mysql.mysql $mysql_dir/tmp
$mysql_dir/bin/mysql_install_db --user=mysql
else
echo "mysql_install_db already installed !"
fi
#check !
ld_so_conf=`cat /etc/ld.so.conf | grep mysql | wc -l`
profile_mysql_bin=`cat /etc/profile | grep mysql | wc -l`
if [ -f "$mysql_cnf_dir" ] || [ -d "$mysql_dir" ];then
echo "ok!"
#
if [ $ld_so_conf = 0 ];then
echo "export PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
fi
#
if [ $profile_mysql_bin = 0 ];then
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
ldconfig
fi
#
else
echo "error! can't install mysql_server please check ! Will now out of the script!"
exit 1
fi
###else
else
echo "mysql_server already installed!"
#
fi
本文出自 “dongnan” 博客,请务必保留此出处http://dngood.blog.51cto.com/446195/629836