標籤:links timeout charset date addgroup use get ati pac
使用指令碼一鍵安裝mysql5.7.x,初始化資料庫。啟動資料庫----mysql版本號碼:原始碼mysql5.7.10linux版本號碼:centos6.5 x86_64#!/bin/bashGROUP_NAME=mysqlUSER_NAME=mysqlMYSQLDB_HOME=/home/mysql/mysqlMYSQLDB_DATA_HOME=/home/mysql/mysql/dataERROR_EXIT=65MYSQL_VERSION="mysql-5.7.10"CMAKE_VERSION="cmake-3.4.3"BOOST_VERSION="boost_1_59_0"CPU_NUMBERS=$(cat /proc/cpuinfo |grep "processor"|wc -l)MYSQL_ID=`ifconfig eth0 | grep "inet addr" | awk -F. ‘{print $4}‘ | awk ‘{print $1}‘`COMPUTER_MEM=`free -m |grep "Mem"|awk ‘{print $2}‘`MYSQL_MEM=`expr $COMPUTER_MEM - $COMPUTER_MEM / 4`echo "$MYSQL_MEM"echo "====================================================="echo "setup MySQL 5.7.10 on centos6.5_64bit "echo "your computer is $CPU_NUMBERS processes ,mysql Memory is $MYSQL_MEM M" echo "you will input mysql‘s root password and mysql‘s memory"echo "====================================================="sleep 1read -n1 -p "are you sure setup[y/n]?" answer case $answer in Y | y) echo echo "start setup....";; N | n) echo echo "Cancel setup...." exit 10 ;; *) echo echo "error input parameter....." exit 11 ;; esac#check if user is rootif [ $(id -u) != "0" ];then echo "Error: You must be root to run this script!" exit 1fi#addGroupif [ -z $(cat /etc/group|awk -F: ‘{print $1}‘| grep -w "$GROUP_NAME") ]then groupadd $GROUP_NAME if(( $? == 0 )) then echo "group $GROUP_NAME add sucessfully!" fi else echo "$GROUP_NAME is exsits"fi #addUserif [ -z $(cat /etc/passwd|awk -F: ‘{print $1}‘| grep -w "$USE_NAME") ]then adduser -g $GROUP_NAME $USER_NAME if (( $? == 0 )) then echo "user $USER_NAME add sucessfully!" fielse echo "$USER_NAME is exsits"fi for i in make gcc-c++ bison-devel ncurses-devel perl perl-devel wgetdo yum -y install $i done ####down lib:System Requirements,CMAKE>=2.8,BOOST>=1.59.0rm -rf /tmp/cmake-3.4*wget https://cmake.org/files/v3.4/${CMAKE_VERSION}.tar.gz -P /tmp if(( $? == 0 )) then echo "cmake DownLoad sucessfully!" else echo "cmake DownLoad failed!" exit $ERROR_EXIT ficd /tmptar xzvf ${CMAKE_VERSION}.tar.gz cd ${CMAKE_VERSION}./bootstrapmake && make installyum install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel -yrm -rf /tmp/boost_1_59*wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/${BOOST_VERSION}.tar.gz -P /tmp if(( $? == 0 )) then echo "boost DownLoad sucessfully!" else echo "boost DownLoad failed!" exit $ERROR_EXIT ficd /tmptar xzvf ${BOOST_VERSION}.tar.gzcd ${BOOST_VERSION}./bootstrap.sh./b2 install#downMySQL rm -rf /tmp/mysql-5.7.* wget http://downloads.mysql.com/archives/get/file/${MYSQL_VERSION}.tar.gz -P /tmp if(( $? == 0 )) then echo "MySQL DownLoad sucessfully!" else echo "MySQL DownLoad failed!" exit $ERROR_EXIT ficd /tmptar xzvf ${MYSQL_VERSION}.tar.gzcd ${MYSQL_VERSION}if [ -s /etc/my.cnf ]; then mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bakficmake -DCMAKE_INSTALL_PREFIX=/home/mysql/mysql -DMYSQL_DATADIR=/home/mysql/mysql/data -DWITH_BOOST=/usr/local/include/boost -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_cimake -j$CPU_NUMBERS && make install if [ -s /etc/my.cnf ]; thenmv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bakfi#custom set mysql mem#MYSQL_MEM="800M" #echo -e "please input Mysql Memory ,like 1G ,1M !"#read -p "(Default Memory is: 800M):" MYSQL_MEM#if [ "$MYSQL_MEM" = "" ];then# MYSQL_MEM="800M"#fi#set mysql root passwordecho "==========================="mysqlrootpwd="root"echo -e "Please input the root password of mysql:"read -p "(Default password: root):" mysqlrootpwdif [ $mysqlrootpwd = "" ]then mysqlrootpwd="root"fiecho "MySQL root‘s password is $mysqlrootpwd"echo "================================="mkdir -p $MYSQLDB_HOME/logtouch $MYSQLDB_HOME/log/mysql-error.logtouch $MYSQLDB_HOME/log/mysql-slow.logchown -R mysql:mysql $MYSQLDB_HOMEecho "[mysql]default-character-set=UTF8[client]#default-character-set=UTF8[mysqld]#datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0port = 3306basedir = $MYSQLDB_HOMEdatadir = $MYSQLDB_DATA_HOMEpid-file = $MYSQLDB_HOME/mysql.piduser = mysqlserver-id = $MYSQL_ID#rpl_semi_sync_master_enabled=1#rpl_semi_sync_master_timeout=1000#rpl_semi_sync_slave_enabled=1relay_log_purge=0read_only=0slave-skip-errors=1396lower_case_table_names = 1character-set-server=utf8skip-name-resolveskip-external-lockingback_log = 500max_connections = 500max_connect_errors = 2000open_files_limit = 65535table_open_cache = 128 max_allowed_packet = 64M##thread_concurrency = `expr $CPU_NUMBERS + $CPU_NUMBERS`key_buffer_size = 64Mread_buffer_size = 64Mread_rnd_buffer_size = 16Msort_buffer_size = 16Mjoin_buffer_size = 16Mtmp_table_size = 96Mmax_heap_table_size = 96Mquery_cache_size = 8Mquery_cache_limit = 8Mthread_cache_size = 64log_bin = mysql-binbinlog_format = mixedbinlog_cache_size = 8Msync_binlog = 1max_binlog_cache_size = 8Mmax_binlog_size = 500Mexpire_logs_days = 10log_error = $MYSQLDB_HOME/log/mysql-error.logslow_query_log = 1long_query_time = 1slow_query_log_file = $MYSQLDB_HOME/log/mysql-slow.logdefault_storage_engine = InnoDBinnodb_buffer_pool_size = $MYSQL_MEMinnodb_file_per_table = 1innodb_data_home_dir = $MYSQLDB_DATA_HOMEinnodb_data_file_path = ibdata1:500M;ibdata2:1G:autoextendinnodb_log_group_home_dir = $MYSQLDB_HOMEinnodb_log_file_size = 500Minnodb_log_buffer_size = 20Minnodb_flush_log_at_trx_commit = 1innodb_print_all_deadlocks = 1[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid" >/etc/my.cnf##$MYSQLDB_HOME/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=$MYSQLDB_HOME --datadir=$MYSQLDB_DATA_HOME --user=$USER_NAME####Before MySQL 5.7.6使用mysql_install_db。MySQL 5.7.6 and up使用mysqld${MYSQLDB_HOME}/bin/mysqld --initialize-insecure --basedir=$MYSQLDB_HOME --datadir=$MYSQLDB_DATA_HOME --user=$USER_NAMEcp $MYSQLDB_HOME/support-files/mysql.server /etc/init.d/mysqlchmod 755 /etc/init.d/mysqlchkconfig --add mysqlchkconfig mysql on/etc/init.d/mysql start cat >> /etc/profile <<EOFPATH=$MYSQLDB_HOME/bin:\$PATHexport PATHEOFsource /etc/profilemysqladmin -u root password $mysqlrootpwdecho "set up successfully!enjoy it...."exit 0
shell指令碼一鍵安裝mysql5.7.x