mysql 5.7安装脚本
[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安装脚本的更多相关文章
- mysql多实例安装脚本
#! /bin/bash # v.mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz # only install master mysql # time:2016-0 ...
- [svc]lnmp一键安装脚本(含有np与mysql分离)
基于lanny一键安装包:(含lnmp所需软件及配置文件) 安装nginx: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliy ...
- mysql 自动备份和nginx自动安装脚本
一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...
- 【排障】编译安装Mysql并使用自启动脚本mysqld后报错
本文用于记录在某次个人实验搭建DZ论坛,在编译安装部署mysql环节时出的错到最终排除错误的过程, 前面采用DZ官网所采用的编译安装mysql的过程就省去,主要从报错处开始讲述. (题外话,经此一役后 ...
- MySQL安装脚本0104-亲试ok
#!/bin/bash export host_ip=192.168.7.79 export password=123456 echo '#1.取master主机ip的后三位作为master的se ...
- MySQL安装脚本最佳实践
MySQL安装脚本最佳实践 2018年9月19日 17:01 #!/bin/bash export host_ip=192.168.7.206 echo '#1.取master主机ip的后三位 ...
- shell脚本专题之-----------全自动编译安装mysql(免安装版)
mysql的编译安装,在博客 开源服务专题之--------mysql的编译安装 中已经说明了,但是还是比较麻烦,尤其是一大堆命令,来手动执行,稍有不慎,就会出错.生产上一般都是先在本地测试环境进行自 ...
- mysql自动化安装脚本(二进制安装)
为了日后安装数据库方便,遂写了一个自动安装MySQL的脚本: 测试可以安装mariadb和MySQL-5.7.X 安装前配置好对应的my.cnf文件放在/tmp路径下 将启动脚本mysql3306放在 ...
- jdk+tomcat+mysql一键安装脚本
最近在搞一个web项目部署,每次都要安装jdk.配置环境变量.安装tomcat和mysql.对于非开发人员,还是有点难度的,经常出错,然后就整理了一个自动化的脚本. JDKinstall.bat @e ...
随机推荐
- gridview合并单元格
记录用,以前写过,忘记了转自:http://marss.co.ua/MergingCellsInGridView.aspx public class GridDecorator { public st ...
- 解决libpython2.6.so.1.0: cannot open shared object file
文章解决的问题:安装nginx中需要Python2.6的支持,下面介绍如何安装Python2.6,并建立lib的连接. 问题展示:error while loading shared librarie ...
- [一]初识Poi
示例代码: package com.lxl.poi; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSS ...
- 校友信息管理系统&SNS互动平台之用户需求及概要设计
前言.提纲及说明: 请移步:<校友信息管理&SNS互动平台之前言.目录及说明>(博客园地址:http://www.cnblogs.com/s6cn/p/3516876.html) ...
- Delphi- 连接MySQL数据库BDE
Delphi使用ADO可以连接MSSQL和ACCESS,但似乎不能连接MYSQL和ORACEL,如果要连接MYSQL和ORACLE得使用BDE. 一.连接方法 首先得先安装mysql驱动程序_mysq ...
- Visual C++中的编译器优化
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:Visual C++中的编译器优化.
- .NET托管代码和非托管代码
.net托管代码是运行在.NET FRAMEWORK上的,类似于JAVA虚拟机托管代码:属安全代码,因为不涉及指针,但相对性能上较低,C#写出来的东西就可以认为是托管代码非托管代码:非安全的,可以使用 ...
- WebSerivce测试工具 Storm
STORM 是一款免费且开源的WebSerivce测试工具 它的功能: 1,测试任意语言测试 WebService 2,可动态调用webservice的方法,即使输入参数需要使用复杂的数据类型 3,节 ...
- ZooKeeper场景实践:(6)集群监控和Master选举
1. 集群机器监控 这通经常使用于那种对集群中机器状态,机器在线率有较高要求的场景,可以高速对集群中机器变化作出响应.这种场景中,往往有一个监控系统,实时检測集群机器是否存活. 利用ZooKeeper ...
- 微信.NET 微信开发 自己主动内容回复 ASP.NET C#代码
微信开发中,首先遇到的问题就是处理怎样接收和响应用户消息 , 本文将向大家介绍一下方法和关键的代码. 本文使用的接口库是 :https://github.com/chendong152/Weixin ...