[root@HE2 ~]# cat mysql_auto_install.sh
###### 二进制自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可###############
######数据库目录/usr/local/mysql############
######数据目录/data/mysql############
######慢日志目录/data/slowlog############
######端口号默认3306其余参数按需自行修改############ ##################
#author ##################
#!/bin/bash # Check if user is root
if [ $(id -u) != "" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit
fi clear
echo "========================================================================="
echo "A tool to auto-compile & install MySQL 5.7.15 on Redhat/CentOS Linux "
echo "========================================================================="
cur_dir=$(pwd) #set mysql root password
echo "===========================" mysqlrootpwd="MANAGER"
echo -e "Please input the root password of mysql:"
read -p "(Default password: MANAGER):" mysqlrootpwd
if [ "$mysqlrootpwd" = "" ]; then
mysqlrootpwd="MANAGER"
fi
echo "==========================="
echo "MySQL root password:$mysqlrootpwd"
echo "===========================" #which MySQL Version do you want to install?
echo "===========================" isinstallmysql57="n"
echo "Install MySQL 5.7.15,Please input y"
read -p "(Please input y , n):" isinstallmysql57 case "$isinstallmysql57" in
y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)
echo "You will install MySQL 5.7.15" isinstallmysql57="y"
;;
*)
echo "INPUT error,You will exit install MySQL 5.7.15" isinstallmysql57="n"
exit
esac get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
#dd if=/dev/tty bs= count= > /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start...or Press Ctrl+c to cancel"
char=`get_char` # Initialize the installation related content.
function InitInstall()
{
cat /etc/issue
uname -a
MemTotal=`free -m | grep Mem | awk '{print $2}'`
echo -e "\n Memory is: ${MemTotal} MB "
#Set timezone
#rm -rf /etc/localtime
#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #Delete Old Mysql program
rpm -qa|grep mysql
rpm -e mysql #Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
setenforce } #Installation of depend on and optimization options.
function InstallDependsAndOpt()
{
cd $cur_dir cat >>/etc/security/limits.conf<<EOF
* soft nproc
* hard nproc
* soft nofile
* hard nofile
EOF echo "fs.file-max=65535" >> /etc/sysctl.conf
} #Install MySQL
function InstallMySQL57()
{
echo "============================Install MySQL 5.7.15=================================="
cd $cur_dir #Backup old my.cnf
#rm -f /etc/my.cnf
if [ -s /etc/my.cnf ]; then
mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak
fi echo "============================MySQL 5.7.15 installing…………========================="
#mysql directory configuration
tar xvf /root/mysql-5.7.-linux-glibc2.-x86_64.tar.gz
mv /root/mysql-5.7.-linux-glibc2.-x86_64 /usr/local/mysql
groupadd mysql -g
useradd -u -g mysql -s /sbin/nologin -d /home/mysql mysql
mkdir -p /data/mysql
mkdir -p /data/slowlog
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/slowlog #edit /etc/my.cnf
SERVERID=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'`
cat >>/etc/my.cnf<<EOF
[client]
port=
socket=/tmp/mysql.sock
default-character-set=utf8 [mysql]
no-auto-rehash
default-character-set=utf8 [mysqld]
port=
character-set-server=utf8
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
explicit_defaults_for_timestamp=true
lower_case_table_names=
back_log=
max_connections=
max_connect_errors=
table_open_cache=
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=
query_cache_size=32M
#query_cache_limit=4M
transaction_isolation=REPEATABLE-READ
tmp_table_size=96M
max_heap_table_size=96M ###***slowqueryparameters
long_query_time=
slow_query_log =
slow_query_log_file=/data/slowlog/slow.log ###***binlogparameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=4096M
max_binlog_size=1024M
binlog_format=MIXED
expire_logs_days= ###***relay-logparameters
#relay-log=/data//relay-bin
#relay-log-info-file=/data//relay-log.info
#master-info-repository=table
#relay-log-info-repository=table
#relay-log-recovery= #***MyISAMparameters
key_buffer_size=16M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=1M #skip-name-resolve ###***master-slavereplicationparameters
server-id=$SERVERID
#slave-skip-errors=all #***Innodbstorageengineparameters
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
#innodb_file_io_threads=
innodb_thread_concurrency=
innodb_flush_log_at_trx_commit=
innodb_log_buffer_size=16M
innodb_log_file_size=512M
innodb_log_files_in_group=
innodb_max_dirty_pages_pct=
innodb_buffer_pool_dump_pct=
innodb_lock_wait_timeout=
innodb_file_per_table=on [mysqldump]
quick
max_allowed_packet=32M [myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M [mysqld_safe]
open-files-limit=
log-error=/data/mysql/error.log
pid-file=/data/mysql/mysqld.pid EOF /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql --initialize-insecure cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level mysqld on cat >> /etc/ld.so.conf.d/mysql-x86_64.conf<<EOF
/usr/local/mysql/lib
EOF
ldconfig if [ -d "/proc/vz" ];then
ulimit -s unlimited
fi /etc/init.d/mysqld start cat >> /etc/profile <<EOF
export PATH=$PATH:/usr/local/mysql/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib
EOF /usr/local/mysql/bin/mysqladmin -u root password $mysqlrootpwd cat > /tmp/mysql_sec_script<<EOF
use mysql;
delete from mysql.user where user!='root' or host!='localhost';
grant all privileges on *.* to 'sys_admin'@'%' identified by 'MANAGER';
flush privileges;
EOF /usr/local/mysql/bin/mysql -u root -p$mysqlrootpwd -h localhost < /tmp/mysql_sec_script #rm -f /tmp/mysql_sec_script #/etc/init.d/mysqld restart echo "============================MySQL 5.7.15 install completed========================="
} function CheckInstall()
{
echo "===================================== Check install ==================================="
clear
ismysql=""
echo "Checking..." if [ -s /usr/local/mysql/bin/mysql ] && [ -s /usr/local/mysql/bin/mysqld_safe ] && [ -s /etc/my.cnf ]; then
echo "MySQL: OK"
ismysql="ok"
else
echo "Error: /usr/local/mysql not found!!!MySQL install failed."
fi if [ "$ismysql" = "ok" ]; then
echo "Install MySQL 5.7.15 completed! enjoy it."
echo "========================================================================="
netstat -ntl
else
echo "Sorry,Failed to install MySQL!"
echo "You can tail /root/mysql-install.log from your server."
fi
} #The installation log
InitInstall >& | tee /root/mysql-install.log
InstallDependsAndOpt >& | tee -a /root/mysql-install.log
InstallMySQL57 > /dev/null
CheckInstall >& | tee -a /root/mysql-install.log

mysql 5.7安装脚本的更多相关文章

  1. mysql多实例安装脚本

    #! /bin/bash # v.mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz # only install master mysql # time:2016-0 ...

  2. [svc]lnmp一键安装脚本(含有np与mysql分离)

    基于lanny一键安装包:(含lnmp所需软件及配置文件) 安装nginx: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliy ...

  3. mysql 自动备份和nginx自动安装脚本

    一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...

  4. 【排障】编译安装Mysql并使用自启动脚本mysqld后报错

    本文用于记录在某次个人实验搭建DZ论坛,在编译安装部署mysql环节时出的错到最终排除错误的过程, 前面采用DZ官网所采用的编译安装mysql的过程就省去,主要从报错处开始讲述. (题外话,经此一役后 ...

  5. MySQL安装脚本0104-亲试ok

    #!/bin/bash export host_ip=192.168.7.79 export password=123456   echo '#1.取master主机ip的后三位作为master的se ...

  6. MySQL安装脚本最佳实践

    MySQL安装脚本最佳实践 2018年9月19日 17:01 #!/bin/bash   export host_ip=192.168.7.206   echo '#1.取master主机ip的后三位 ...

  7. shell脚本专题之-----------全自动编译安装mysql(免安装版)

    mysql的编译安装,在博客 开源服务专题之--------mysql的编译安装 中已经说明了,但是还是比较麻烦,尤其是一大堆命令,来手动执行,稍有不慎,就会出错.生产上一般都是先在本地测试环境进行自 ...

  8. mysql自动化安装脚本(二进制安装)

    为了日后安装数据库方便,遂写了一个自动安装MySQL的脚本: 测试可以安装mariadb和MySQL-5.7.X 安装前配置好对应的my.cnf文件放在/tmp路径下 将启动脚本mysql3306放在 ...

  9. jdk+tomcat+mysql一键安装脚本

    最近在搞一个web项目部署,每次都要安装jdk.配置环境变量.安装tomcat和mysql.对于非开发人员,还是有点难度的,经常出错,然后就整理了一个自动化的脚本. JDKinstall.bat @e ...

随机推荐

  1. 局域网内Linux服务器时间同步

    局域网内Linux服务器时间同步   1.将一台能够上网的服务器作为时间服务器:  # /usr/bin/rdate -s time-b.timefreq.bldrdoc.gov //将时间服务器与互 ...

  2. hdoj 3861 The King’s Problem【强连通缩点建图&&最小路径覆盖】

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. 对比iOS网络组件:AFNetworking VS ASIHTTPRequest(转载)

    在开发iOS应用过程中,如何高效的与服务端API进行数据交换,是一个常见问题.一般开发者都会选择一个第三方的网络组件作为服务,以提高开发效率和稳定性.这些组件把复杂的网络底层操作封装成友好的类和方法, ...

  4. Delphi 第三方组件

    TMS Component Pack v7.0.0.0 TMS Component Pack 版本为Delphi和C++ Builder提供了超过350个VCL组件,用以创建功能丰富的.现代的和原生W ...

  5. strlen和sizeof的差别

    一.sizeof     sizeof(...)是运算符,而不是一个函数.     一个简单的样例: int a; cout<<sizeof a<<endl;     在头文件 ...

  6. SpringMVC + ehcache( ehcache-spring-annotations)基于注解的服务器端数据缓存

    背景 声明,如果你不关心java缓存解决方案的全貌,只是急着解决问题,请略过背景部分. 在互联网应用中,由于并发量比传统的企业级应用会高出很多,所以处理大并发的问题就显得尤为重要.在硬件资源一定的情况 ...

  7. 标准I/O库之临时文件

    ISO C标准I/O库提供了两个函数以帮助创建临时文件. #include <stdio.h> char *tmpnam( char *ptr ); 返回值:指向唯一路径名的指针 FILE ...

  8. jQuery动态实现title的修改 失效问题

    最近做了一个网站,一切都很顺利,在上线的时候,突然发现一个严重的问题,开始面对这个问题,完全不知所措(在goole.火狐.IE9及其以上都没得问题:IE8及其低版本都失效)只是浏览器弹出一个bug,但 ...

  9. Android自定义View之ProgressBar出场记

    关于自定义View,我们前面已经有三篇文章在介绍了,如果筒子们还没阅读,建议先看一下,分别是android自定义View之钟表诞生记.android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检 ...

  10. NIO学习:buffer读入与写出(文件复制示例)

    FileInputStream fInputStream=new FileInputStream(new File("/root/Desktop/testImage.jpg")); ...