标签:mysql脚本
#!/bin/bash
mysql_install_dir=/usr/local/mysqlmysql_data_dir=/data/mysqlmysql_6_version=5.6.26dbrootpwd=rootMem=`free -m | awk ‘/Mem:/{print $2}‘`Swap=`free -m | awk ‘/Swap:/{print $2}‘`Install_MySQL-5-6(){yum -y install make gcc-c++ cmake bison-devel ncurses-develwget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-${mysql_6_version}.tar.gzid -u mysql >/dev/null 2>&1[ $? -ne 0 ] && useradd -M -s /sbin/nologin mysqlmkdir -p $mysql_data_dir;chown mysql.mysql -R $mysql_data_dirtar zxf mysql-${mysql_6_version}.tar.gzcd mysql-$mysql_6_versionmake clean[ ! -d "$mysql_install_dir" ] && mkdir -p $mysql_install_dircmake . -DCMAKE_INSTALL_PREFIX=$mysql_install_dir \-DMYSQL_DATADIR=$mysql_data_dir \-DSYSCONFDIR=/etc \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DENABLED_LOCAL_INFILE=1 \-DENABLE_DTRACE=0 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8mb4 \-DDEFAULT_COLLATION=utf8mb4_general_ci \-DWITH_EMBEDDED_SERVER=1 \make -j `grep processor /proc/cpuinfo | wc -l`make installif [ -d "$mysql_install_dir/support-files" ];then echo "${CSUCCESS}MySQL install successfully! ${CEND}" cd .. rm -rf mysql-$mysql_6_versionelse rm -rf $mysql_install_dir echo "${CFAILURE}MySQL install failed, Please contact the author! ${CEND}" kill -9 $$fi/bin/cp $mysql_install_dir/support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldchkconfig mysqld oncd ..[ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}$mysql_install_dir/scripts/mysql_install_db --user=mysql --basedir=$mysql_install_dir --datadir=$mysql_data_dirchown mysql.mysql -R $mysql_data_dirservice mysqld start[ -z "`grep ^‘export PATH=‘ /etc/profile`" ] && echo "export PATH=$mysql_install_dir/bin:\$PATH" >> /etc/profile[ -n "`grep ^‘export PATH=‘ /etc/profile`" -a -z "`grep $mysql_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$mysql_install_dir/bin:\1@" /etc/profile. /etc/profile$mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@‘127.0.0.1‘ identified by \"$dbrootpwd\" with grant option;"$mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@‘localhost‘ identified by \"$dbrootpwd\" with grant option;"$mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password=‘‘;"$mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User=‘‘;"$mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!=‘localhost‘;"$mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"$mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.confecho "$mysql_install_dir/lib" > mysql.conf/sbin/ldconfigservice mysqld stop}Install_MySQL-5-6本文出自 “一只菜的不能再菜的小菜鸟” 博客,转载请与作者联系!
标签:mysql脚本
原文地址:http://liliming.blog.51cto.com/10925034/1793764