脚本须知:

  1. 该脚本目前只测试过mysql版本为5.6.x的源码,其他源码可以对本脚本稍作修改即可

  2. 本脚本也可以使用wget mysql源码的方式进行,但考虑到后期提供源码的地址不可用,所以需要手动下载mysql 5.6.x的源码包并放入到/usr/local/src

  3. 此脚本在编译安装过程中禁用了iptables和SElinux策略,如果你在使用iptalbes相关功能请先完成相关配置。

  4. 该脚本主要是对此前尚未装过mysql的linux系统环境而写的,如果此前装过mysql请根据脚本适当修改,主要是在脚本添加判断语句,或者你也可以移除之前的mysql

      版本 (mysql安装路径 配置文件)

5. 本脚本实现的主要功能是mysql 安全初始化安装;提供sysv风格的启动脚本;最基本的配置文件(你可以根据功能需要通过配置然后覆盖/etc/my.cnf实现定制)

  6. mysql 5.6.30源码编译安装 默认没有开启查询缓存,你可以在my.cnf 通过此选项 query_cache_type = ON 来启用

 #!/bin/bash
#
# Description: Automated Deployment compilation MySQL
# Author: jiajunwei
# Version: ---
# Environment:
# . Mysql-Version: mysql-5.6.x
# . Operating system: CentOS .x
# Advise: The MySQL data directory on a logical volume
# Preparation: Need to put the source package mysql-5.6.x.tar.gz to /usr/local/src #####################[Preparatory work before compiling]###################### # . Provide the compiler environment
echo -e "\033[31mThe First step:Check and Configure compile environment ......\033[0m" #if ! ping -c2 -w3 www.baidu.com &> /dev/null;then
# mkdir -p /etc/yum.repos.d/repo
# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo
# cat << EOF > /etc/yum.repos.d/CentOS-Media.repo
# [c6-media]
# name=CentOS-$releasever - Media
# baseurl=file:///media/cdrom/
# gpgcheck=1
# enabled=1
# gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#EOF
# mkdir -p /media/cdrom
# if od -ax /dev/cdrom | head -1 &> /dev/null;then
# umount /dev/cdrom &> /dev/null
# mount -r /dev/cdrom /media/cdrom
# else
# echo "Please mount the disk and load the system image"
# exit 2
# fi
#fi
yum -y groupinstall "Development Tools" &> /dev/null
yum -y install cmake bison ncurses-devel openssl-devel &> /dev/null
if [ $? -eq 0 ];then
echo "--------->Enviroment is ok "
else
echo "--->Failed to compile environment testing, please check"
exit 3
fi # 2. Add the operation of database users
echo -e "\033[31mThe second step:Add the operation of database users with user mysql......\033[0m"
[ ! `grep "mysql" /etc/group` ] && groupadd -r mysql
[ ! `grep "mysql" /etc/passwd` ] && useradd -r -d /mydata/data -g mysql -s /bin/false mysql
if id mysql &> /dev/null;then
echo "--------->Add user complete "
else
echo "--->Add user failed "
exit 4
fi
#[ -f /etc/yum.repos.d/repo/CentOS-Base.repo ] && mv /etc/yum.repos.d/repo/*.repo /etc/yum.repos.d/
# 3. To determine the database directory and modify it belongs to the main group
echo -e "\033[31mThe third step:Determine the data directory and modify the permissions......\033[0m"
mkdir -p /mydata/data
chown -R mysql.mysql /mydata/data
echo "--->OK" ################################[Compile and install MySQL]####################### echo -e "\033[31mThe forth step:Compile and install MySQL......\033[0m"
if ! ls -l /usr/local/src/mysql*.tar.* &> /dev/null;then
echo " Copy your source package to this path:/usr/local/src"
exit 5
fi
tar xf /usr/local/src/mysql*.tar.* -C /usr/local/src
dir_count=`find /usr/local/src/ -maxdepth 1 -type d -name "mysql*" | wc -l`
if [ $dir_count -eq 1 ];then
dir=`find /usr/local/src/ -maxdepth 1 -type d -name "mysql*"`
else
echo "This path cannot have two MySQL directories at the same time"
exit 5
fi
cd $dir
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/data/ \
-DSYSCONFDIR=/etc/ -DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/mydata/data/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_DEBUG=0 -DENABLED_PROFILING=1 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNODB_MEMCACHED=1
cpu_count=`cat /proc/cpuinfo | grep "processor" |wc -l`
make -j $cpu_count && make install
if [ $? -eq 0 ];then
echo "------->installation is complete"
else
echo "--->Compile failed, please check"
exit 6
fi ############################[boot startup script]#######################
echo -e "\033[31mThe Fifth step:Provide configuration files and sysV boot startup script for MySQL......\033[0m"
[ -f /etc/my.cnf ] && \mv -f /etc/my.cnf{,.bak}
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sed -i '/^\[mysqld\]/ a \datadir=/mydata/data\nsocket=/mydata/data/mysql.sock\n \
pid-file=/var/run/mysqld/mysqld.pid\n \
log-error=/var/log/mysqld.log\n \
user=mysql\n \
innodb_file_per_table=ON\n \
skip_name_resolve=ON\n \
log-bin=/mydata/log-bin/mysql-bin' /etc/my.cnf
mkdir -p /var/run/mysqld
chown -R mysql.mysql /var/run/mysqld
mkdir -p /mydata/log-bin
chown -R mysql.mysql /mydata/log-bin
[ -f /etc/init.d/mysqld ] && \mv -f /etc/init.d/mysqld{,.bak}
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
echo "------->OK" #############################[Export binary files]########################
echo -e "\033[31mThe sixth step:Export MySQL related binary files......\033[0m"
echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql-5.6.sh
#source /etc/profile
exec bash
if which mysqld_safe &> /dev/null;then
echo "------>export is successful"
else
echo "--->export is faild"
fi ###########################[MySQL database initialization]##################
echo -e "\033[31mThe seventh step:MySQL database initialization .......\033[0m"
cd /mydata/data
tar -jcf mydata-data.tar.bz2 *
unalias mv -f mydata-data.tar.bz2 /tmp/
rm -rf *
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/mydata/data/ \
--user=mysql
if [ $? -eq 0 ];then
echo "--->initiate is finished "
else
echo "------->initiate is failed "
exit 7
fi ###########################[Database Startup Test]####################
echo -e "\033[31mThe eighth step:Database Startup Test......\033[0m"
# 1. Set firewall and SELinux
service iptables stop
setenforce 0
# 2. Run mysql service
service mysqld start
if netstat -lntp | grep "mysql" &> /dev/null;then
echo "------->Service startup normal "
else
echo "---->Service startup failed "
exit 8
fi ########################[Run security setup script]#####################
echo -e "\033[31mThe last step: Run security setup script......\033[0m"
echo -e "\ny\nmysqldba\nmysqldba\ny\nn\ny\ny\n" | mysql_secure_installation
if [ ! $? -eq 0 ];then
echo "Security initialization failed, please run manually"
fi
echo -e "\033[31mPlease re check and configure the firewall policy and selinux, now they are disabled.\033[0m"

最新文章

  1. Java的动态绑定机制
  2. 因为此版本的应用程序不支持其项目类型(.csproj)”之解
  3. 字典树(codevs 4189)
  4. Goodchild教授关于GIS的四大预测的不同看法
  5. wav 转换到 flac
  6. .NET Reflector 8.3.3.115 官方最新版+注册机(强大的.NET反编译工具破解版)
  7. C++学习笔记33 转换操作符
  8. Microsoft .Net Remoting系列专题之二
  9. mybatis 之 占位符#{} 和 ${}
  10. 计蒜客 无脑博士 bfs
  11. linux定时清理数据库过期记录
  12. Elasticsearch与Hadoop集成大数据处理介绍
  13. Python:Day43 抽屉
  14. A1057. Stack
  15. 微软BI SSIS 2012 辅助阅读博客
  16. 解决 Sublime text3 中文显示乱码问题【亲测可用】
  17. JS中的“==”符号及布尔值转换规则
  18. SpringBoot2 @validated 自定义效验类型
  19. BZOJ 1189 【HNOI2007】 紧急疏散evacuate
  20. 洛谷P3980 [NOI2008]志愿者招募

热门文章

  1. Codevs1033 蚯蚓的游戏
  2. Windows 10 建立wifi热点
  3. 在 Ubuntu 环境下实现插入鼠标自动关闭触摸板
  4. mysql 的 case when 用法
  5. android自动化测试之Monkey--从参数讲解、脚本制作到实战技巧
  6. pandas修改列名
  7. Java技术——Java中创建对象的5种方式
  8. while else语句
  9. hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数
  10. 使用百度siteapp开发网站的App-(IOS和Android版本)