首页 > 代码库 > Centos 6.4上面用Shell脚本一键安装mysql 5.6.15

Centos 6.4上面用Shell脚本一键安装mysql 5.6.15

Centos 6.4上面用Shell脚本一键安装mysql 5.6.15 

 

#!/bin/bashif [ `uname -m` == "x86_64" ];thenmachine=x86_64elsemachine=i686fimysqlBasedir=/storage/server/mysqlmysqlDatadir=${mysqlBasedir}/data/mysqlLogdir=/storage/log/mysqlmysqlUser=mysqlmysqlGroup=mysqlmkdir -p $mysqlBasedirmkdir -p $mysqlDatadirmkdir -p $mysqlLogdir#如果mysql已安装,删除原有mysqlif [ $machine == "x86_64" ];then  rm -rf mysql-5.6.15-linux-glibc2.5-x86_64  if [ ! -f mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz ];then     wget http://oss.aliyuncs.com/aliyunecs/onekey/mysql/mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz  fi  tar -xzvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz  mv mysql-5.6.15-linux-glibc2.5-x86_64/* $mysqlBasedirelse  rm -rf mysql-5.6.15-linux-glibc2.5-i686  if [ ! -f mysql-5.6.15-linux-glibc2.5-i686.tar.gz ];then  wget http://oss.aliyuncs.com/aliyunecs/onekey/mysql/mysql-5.6.15-linux-glibc2.5-i686.tar.gz  fi  tar -xzvf mysql-5.6.15-linux-glibc2.5-i686.tar.gz  mv mysql-5.6.15-linux-glibc2.5-i686/* $mysqlBasedirfi#添加mysql用户组groupadd $mysqlGroup#添加mysql用户 ,并制定组为mysql /sbin/nologin意思是用户不允许登录useradd -g $mysqlGroup -s /sbin/nologin $mysqlUser#安装服务${mysqlBasedir}/scripts/mysql_install_db --datadir=$mysqlDatadir --basedir=$mysqlBasedir --user=$mysqlUser #设置权限chown -R ${mysqlUser}:${mysqlGroup} $mysqlBasedirchown -R ${mysqlUser}:${mysqlGroup} $mysqlDatadirchown -R ${mysqlUser}:${mysqlGroup} $mysqlLogdir#把mysql.server放到/etc/init.d 目录下方便使用\cp -f ${mysqlBasedir}/support-files/mysql.server /etc/init.d/mysqld#脚本里面的这两行在mysql启动文件指定mysql数据库的安装目录和数据目录存放目录sed -i s#^basedir=$#basedir=${mysqlBasedir}# /etc/init.d/mysqldsed -i s#^datadir=$#datadir=${mysqlDatadir}# /etc/init.d/mysqld#配置文件cat > /etc/my.cnf <<END[client]port            = 3306socket          = /tmp/mysql.sock[mysqld]port            = 3306socket          = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mlog-bin=mysql-binbinlog_format=mixedserver-id       = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash[myisamchk]key_buffer_size = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeoutENDchmod 755 /etc/init.d/mysqld/etc/init.d/mysqld start