Linux MySQL5.6.36自动换安装脚本

###### 自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可###############
######数据库目录/data/mysql############
######数据目录/data/mysql/data############
######慢日志目录/data/slowlog############
######端口号默认3306其余参数按需自行修改############

##################
##################
#!/bin/bash
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit 1
fi
clear
echo "========================================================================="
echo "A tool to auto-compile & install MySQL 5.6.36 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 "==========================="
isinstallmysql56="n"
echo "Install MySQL 5.6.36,Please input y"
read -p "(Please input y , n):" isinstallmysql56
case "$isinstallmysql56" in
y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)
echo "You will install MySQL 5.6.36"
isinstallmysql56="y"
;;
*)
echo "INPUT error,You will exit install MySQL 5.6.36"
isinstallmysql56="n"
exit
esac
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
#dd if=/dev/tty bs=1 count=1 2> /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 mariadb program
MARIA=`rpm -qa|grep mariadb`
yum -y remove $MARIA
#Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config
fi
setenforce 0
}

#Installation of depend on and optimization options.
function InstallDependsAndOpt()
{
cd $cur_dir
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
echo "fs.file-max=65535" >> /etc/sysctl.conf
}
#Install MySQL
function InstallMySQL56()
{
echo "============================Install MySQL 5.6.36=================================="
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.6.36 installing…………========================="
#mysql directory configuration
mkdir -p /data/
tar xvf /root/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
mv /root/mysql-5.6.36-linux-glibc2.5-x86_64 /data/mysql
groupadd mysql -g 512
useradd -u 512 -g mysql -s /sbin/nologin -d /home/mysql mysql
touch /data/mysql/mysqld.pid
touch /data/mysql/error.log
mkdir -p /data/slowlog
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /data/slowlog
#edit /etc/my.cnf
SERVERID=`ifconfig eno1 | grep "inet " | awk ‘{ print $2}‘| awk -F. ‘{ print $3$4}‘`
cat >>/etc/my.cnf<<EOF
[client]
port=3306
socket=/tmp/mysql.sock
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
federated
default-storage-engine=INNODB
port=3306
character-set-server=utf8
socket=/tmp/mysql.sock
basedir=/data/mysql
datadir=/data/mysql/data
explicit_defaults_for_timestamp=true
long_query_time=1
slow_query_log =1
slow_query_log_file=/data/slowlog/slow.log
log-bin=mysql-bin
server-id=$SERVERID
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
log-bin-trust-function-creators=1

[mysqld_safe]
log-error=/data/mysql/error.log

EOF

/data/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data --basedir=/data/mysql

cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 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

/data/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 ‘vvnt‘@‘192.168.%‘ identified by ‘[email protected]‘;
drop database test;
flush privileges;
EOF

/data/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 ‘PATH=/data/mysql/bin/:$PATH‘ >>/etc/profile

source /etc/profile

echo "============================MySQL 5.6.36 install completed========================="
}

function CheckInstall()
{
echo "===================================== Check install ==================================="
clear
ismysql=""
echo "Checking..."

if [ -s /data/mysql/bin/mysql ] && [ -s /data/mysql/bin/mysqld_safe ] && [ -s /etc/my.cnf ]; then
echo "MySQL: OK"
ismysql="ok"
else
echo "Error: /data/mysql not found!!!MySQL install failed."
fi

if [ "$ismysql" = "ok" ]; then
echo "Install MySQL 5.6.36 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 2>&1 | tee /root/mysql-install.log
InstallDependsAndOpt 2>&1 | tee -a /root/mysql-install.log
InstallMySQL56 > /dev/null
CheckInstall 2>&1 | tee -a /root/mysql-install.log

#deletion of installation packages and script files
find /root -type f -name ‘mysql*‘ -exec rm -rf {} \;

原文地址:https://www.cnblogs.com/qiming0322/p/10133163.html

时间: 2024-10-07 05:29:07

Linux MySQL5.6.36自动换安装脚本的相关文章

Linux环境下JDK/Eclipse一键安装脚本

-------------------------------------------------------------------- author:jiangxin Email:[email protected] Blog:http://blog.csdn.net/jiangxinnju -------------------------------------------------------------------- 假设大家必须在Linux环境下使用java开发应用程序,会感觉Lin

Linux使用expect实现自动登录的脚本

前提条件服务器已经安装过tcl和expect, 若未安装:可以先执行 yum  install tcl  expect  进行安装 第一步.编写以下自动登录脚本login.sh ############################################## #!/usr/bin/expectset timeout 10 spawn ssh username@172.16.2.1expect "password:"send "password\r"int

MySQL-5.6.36编译安装教程,新手必看!

首先MySQL是关系型数据库,什么是关系型关系型数据库,优缺点我们也讲了,在上一篇博客:https://blog.51cto.com/14573101/2447264 现在我们来说一说,MySQL的安装方式有哪几种:1.RPM|yum安装速度快,安装方便,不能定制2.二进制:无须安装,解压即用,不能定制3.编译安装:安装慢,可定制5.5之前: ./configure make make install 5.5之后:cmake gmake4.先编译,然后制作rpm,制作yum库,接着yum安装简便

linux下PXE无人值守环境自动安装脚本

当时单位要安装一套linux的PXE无人值守装机程序,装完后花了九牛二虎之力写了一个自动安装脚本,以便今后安全方便,不过后来就没怎么用了,甚至都有些淡忘了,哈哈,分享出来,有研究PXE自动安装的可以看看,在使用的时候里面的ip地址要换掉的. #!/bin/sh #writer:gaolixu yum -y install dhcp tftp-server vsftpd syslinux xinetd if ! service dhcpd status ;then ############### 

如何在linux平台上安装redis(附自动安装脚本)

1.Redis的简单介绍 Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集合和有序集合.支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能.所以Redis也可以被看成是一个数据结构服务器. Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这被称为"半持久化模式");也可以把每一次数据变化都写到一个append onlyfile(aof)里

Linux中自动安装脚本

如何让你的主机自动的完成安装,自动的回答系统提出的问题,编写自动安装脚本即可实现,如下将详细解释自动脚本安装方法. systemd-config-kickstart  ##自动应答脚本制作工具 安装成功,在安装过程中systemd-config-kickstart 将做出脚本应答 进行选择语言选择 (1)Basic Configuration 安装过程的必须一致时区选择(可不选,在脚本中都有写到,这里做一个解释) Root passwd 填写Root密码,并确认,两次输入密码 Advanced

python3自动安装脚本,python3.x与python2.x共存

1.前言: python3过程中,通过搜索一些文章参考安装过程发现比较麻烦,而且还出现一些不可预期的报错.python3环境需要升级openssl,所以为了部署到其他环境更方便,写自动安装脚本方式,且安装模式为python3.x与python2.x共存,防止可能发生原有环境异常的情况. 现在我把脚本分享出来,希望可以帮助到有需要的人,业务采集监控python脚本文件不提供,因为那些跟实际业务开发关联比较紧,比较没有参考意义也不方便公开. shell自动安装脚本,只需按说明简单修改配置,和调用集成

mysql自动安装脚本

为适应自己工作习惯和需要,花一点时间写了一个mysql自动安装脚本,供大家参考学习. 注意: 1.需要先安装cmake 2.数据库版本需要在第二步安装mysql时修改 3.该脚本是以root用户安装并启动 脚本内容如下: ######################################################################## #mysql自动安装脚本,其中变量/mysql_v_dir/和/port/可根据实际需要修改    # #执行脚本命令:sh mys

ipvsadm+keepalived+inotify-tools自动安装脚本

#!/bin/bash # # #this is install keepalived+lvs-DR # # tar_dir=/usr/src configure_yum() { echo "[rhel-local]">/etc/yum.repos.d/rhel-local.repo echo "baseurl=file:///media/Server">>/etc/yum.repos.d/rhel-local.repo echo "en