shell脚本一键安装MySQL5.7.29的方法

本文参考51CTO博客作者wjw555的作品

脚本内容:

vim install.mysql.sh

#!/bin/bash

[ -f /etc/init.d/functions ]&& . /etc/init.d/functions

###Check if user is root
if [ $UID -ne 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.7.29 on Redhat/CentOS Linux "
echo "========================================================================="
#pkill -9 mysql
#date +%Y-%m-%d-%H-%M
#卸载系统自带的Mysql
#/bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps
#/bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps
#/bin/rm -f /etc/my.cnf

#set mysql root password
 echo "==========================="
  mysqlrootpwd="$1"
  if [ "$1" = "" ]; then
    mysqlrootpwd="rootmysql"
  fi

#which MySQL Version do you want to install?
echo "==========================="

 isinstallmysql57="5.7.29"
 echo "Install MySQL 5.7.29,Please input y"
 read -p "(Please input y , n):"
# Initialize the installation related content.
 #Delete Old Mysql program
 rpm -qa|grep mysql
 rpm -e mysql

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

echo "============================Install MySQL 5.7.29=================================="

#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.29 installing…………========================="

##define mysql directory configuration variable
Datadir=/data/mysql/data
Binlogdir=/data/mysql/binlog
Logdir=/data/mysql/logs

##yum install devel and wget mysql
yum install numactl
/usr/bin/wget -P /tmp http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
sleep 2
tar xf /tmp/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -s /usr/local/mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql
grep mysql /etc/passwd
RETVAL=$?
if [ $RETVAL -ne 0 ];then
 useradd mysql -s /sbin/nologin -M
  action "mysql user added successfully" /bin/true
 else
  action " $(echo -e "\e[31;47;5m mysql user already exists\e[0m")" /bin/false
fi

if [ ! -d "$Datadir" ]
then
 mkdir -p /data/mysql/data
fi

if [ ! -d "$Binlogdir" ]
then
 mkdir -p /data/mysql/binlog
fi

if [ ! -d "$Logdir" ]
then
 mkdir -p /data/mysql/logs
fi

chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /usr/local/mysql

#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   = 3306

[mysql]
auto-rehash
prompt="\\u@\\h [\\d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log

[mysqld]
####: for global
user        =mysql
basedir        =/usr/local/mysql/
datadir        =/data/mysql/data
server_id       =2333306
port        =3306
character_set_server    =utf8
explicit_defaults_for_timestamp  =off
log_timestamps      =system
socket        =/tmp/mysql.sock
read_only       =0
skip_name_resolve     =1
auto_increment_increment   =1
auto_increment_offset    =1
lower_case_table_names    =1
secure_file_priv     =
open_files_limit     =65536
max_connections      =1000
thread_cache_size     =64
table_open_cache     =81920
table_definition_cache    =4096
table_open_cache_instances   =64
max_prepared_stmt_count    =1048576      

####: for binlog
binlog_format      =row
log_bin        =/data/mysql/binlog/mysql-bin
binlog_rows_query_log_events  =on
log_slave_updates     =on
expire_logs_days     =7
binlog_cache_size     =65536
#binlog_checksum     =none
sync_binlog       =1
slave-preserve-commit-order   =ON       

####: for error-log
log_error       =/data/mysql/logs/error.log      

general_log       =off
general_log_file     =/data/mysql/logs/general.log     

####: for slow query log
slow_query_log      =on
slow_query_log_file     =/data/mysql/logs/slow.log
#log_queries_not_using_indexes  =on
long_query_time      =1.000000      

####: for gtid
#gtid_executed_compression_period =1000
gtid_mode       =on
enforce_gtid_consistency   =on        

####: for replication
skip_slave_start      =1
#master_info_repository    =table
#relay_log_info_repository   =table
slave_parallel_type     =logical_clock
slave_parallel_workers    =4
#rpl_semi_sync_master_enabled  =1
#rpl_semi_sync_slave_enabled   =1
#rpl_semi_sync_master_timeout  =1000
#plugin_load_add      =semisync_master.so
#plugin_load_add      =semisync_slave.so
binlog_group_commit_sync_delay  =100
binlog_group_commit_sync_no_delay_count = 10      

####: for innodb
default_storage_engine       =innodb
default_tmp_storage_engine      =innodb
innodb_data_file_path       =ibdata1:1024M:autoextend
innodb_temp_data_file_path      =ibtmp1:12M:autoextend
innodb_buffer_pool_filename      =ib_buffer_pool
innodb_log_group_home_dir      =/data/mysql/data
innodb_log_files_in_group      =3
innodb_log_file_size       =1024M
innodb_file_per_table       =on
innodb_online_alter_log_max_size    =128M
innodb_open_files        =65535
innodb_page_size        =16k
innodb_thread_concurrency      =0
innodb_read_io_threads       =4
innodb_write_io_threads       =4
innodb_purge_threads       =4
innodb_page_cleaners       =4
     # 4(刷新lru脏页)
innodb_print_all_deadlocks      =on
innodb_deadlock_detect       =on
innodb_lock_wait_timeout      =20
innodb_spin_wait_delay       =128
innodb_autoinc_lock_mode      =2
innodb_io_capacity        =200
innodb_io_capacity_max       =2000
#--------Persistent Optimizer Statistics
innodb_stats_auto_recalc      =on
innodb_stats_persistent       =on
innodb_stats_persistent_sample_pages   =20      

innodb_adaptive_hash_index      =on
innodb_change_buffering       =all
innodb_change_buffer_max_size     =25
innodb_flush_neighbors       =1
#innodb_flush_method        =
innodb_doublewrite        =on
innodb_log_buffer_size       =128M
innodb_flush_log_at_timeout      =1
innodb_flush_log_at_trx_commit     =1
innodb_buffer_pool_size       =4096M
innodb_buffer_pool_instances     =4
autocommit          =1
#--------innodb scan resistant
innodb_old_blocks_pct       =37
innodb_old_blocks_time       =1000
#--------innodb read ahead
innodb_read_ahead_threshold      =56
innodb_random_read_ahead      =OFF
#--------innodb buffer pool state
innodb_buffer_pool_dump_pct      =25
innodb_buffer_pool_dump_at_shutdown    =ON
innodb_buffer_pool_load_at_startup    =ON      

EOF

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
Pass=$(grep 'A temporary password' /data/mysql/logs/error.log |awk '{print $NF}')
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
echo "============================MySQL 5.7.29 install completed========================="
ps -eo start,cmd,pid|grep mysql
/usr/local/mysql/bin/mysqladmin -uroot -p"$Pass" password $mysqlrootpwd
[root@localhost ~]# sh install.mysql.sh mysqlroot
[root@localhost ~]# source /etc/profile.d/mysql.sh

说明: mysqlroot 为安装脚本修改MySQL服务默认密码后的新的密码

[root@localhost ~]# mysql -uroot -p'mysqlroot' -e "select now()"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------+
| now()    |
+---------------------+
| 2020-10-13 16:18:47 |
+---------------------+

到此处MySQL服务启动成功!

总结

到此这篇关于shell脚本一键安装MySQL5.7.29 的文章就介绍到这了,更多相关shell脚本一键安装MySQL内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Centos7安装 mysql5.6.29 shell脚本

    本文实例为大家分享了mysql5.6.29的shell脚本,供大家参考,具体内容如下 创建脚本mysql.sh,直接运行sh mysql.sh #!/bin/bash if [ -d /software ] ;then cd /software else mkdir /software && cd /software fi #is exist command ,if not,yum install is_exist() { which $1 if [ $? -ne 0 ] ;then yu

  • MySQL5.7安装过程并重置root密码的方法(shell 脚本)

    由于 MySQL 5.7 版本的 root 密码是首次启动时随机生成的,并且还要求必须修改后才能使用,所以有了本文:使用 shell 脚本完成安装和设置新的 root 密码. 以官方的 rpm 包安装为例,先下载,使用 yum 命令安装,如果有需要的依赖包会自动安装 wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-1.el6.x86_64.rpm-bundle.tar tar xf mysql-5.7.17-1.el6

  • shell脚本一键安装MySQL5.7.29的方法

    本文参考51CTO博客作者wjw555的作品 脚本内容: vim install.mysql.sh #!/bin/bash [ -f /etc/init.d/functions ]&& . /etc/init.d/functions ###Check if user is root if [ $UID -ne 0 ]; then echo "Error: You must be root to run this script, please use root to install

  • shell脚本一键安装php7的实例(推荐)

    如下所示: #!/bin/bash php_gz_file='/home/php/Downloads/source/php-7.0.0.tar.bz2' tar_dir='/home/php/Downloads/dst/' source_dir='php-7.0.0' cd $tar_dir rm -rf $source_dir echo '===start tar php ========' tar -jxvf $php_gz_file > /dev/null echo '===end tar

  • Shell脚本一键安装Nginx服务自定义Nginx版本

    经常安装Nginx服务,有时候要安装的版本不同就很烦,然后写了一个可以自定义Nginx版本的脚本(嗯,在朋友的帮助下,哈哈). 话不多少,内容如下: #!/bin/bash #Nginx版本 ver=nginx-1.$2.$3 # 安装目录 in_dir="/app/$ver" #软件存放目录 dl_dir="/server" #最终运行目录 run_dir=/app/nginx if [ ! -d $in_dir ];then mkdir -p $in_dir f

  • 使用shell脚本一键部署LNMP架构的方法

    LNMP架构介绍 LNMP:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器.Mysql是一个小型关系型数据库管理系统.PHP是一种在服务器端执行的嵌入HTML文档的脚本语言. 原理:浏览器发送http request请求到服务器(Nginx),服务器响应并处理web请求,将一些静态资源(CSS,图片,视频等)保存服务器上,然后将php脚本通过接口传输协议(网关协议)PHP-FCGI

  • 一键安装mysql5.7及密码策略修改方法

    一.一键安装Mysql脚本 [root@uat01 ~]# cat InstallMysql01.sh #!/bin/bash #2018-10-13 #旅行者-Travel #1.安装wget yum -y install wget #2.下载mysql的yum源 URL="https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm" wget $URL -P /etc/yum.repos.d/ yum -y

  • Centos7下源码安装Python3 及shell 脚本自动安装Python3的教程

    一.源码安装 首先安装开发工具包 yum groupinstall -y "Development tools" 安装依赖软件包 yum -y install gcc gcc-c++ zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel wget 上Python 官网 找源码包的下载地址 wget https://www.python.org/ftp/python/3.7.6/Pyth

  • shell脚本一键同时推送代码至github和gitee的解决办法

    自己写的东西,要同时推送多个git地址,解决办法如下: 1.先要初始化你的git              进入自己的项目目录,然后执行 git  init cd /app/code/go-study git init 2.执行以下脚本: #!/bin/bash #author Oliver #since 2020-09-03 15:24:31 git remote rm origin #replace your git location git remote add origin 'https

  • shell脚本自动安装jdk的方法示例

    1.安装准备 1.jdk-8u221-linux-x64.tar.gz jdk压缩包(需要放在opt目录下) 2.shell脚本 2.shell命令 Sed 对字符的处理 -p 显示,将某个选择的数据打印显示.通常 p 会与参数 sed -n 一起执行 -d 删除,显示模式空间删除指定行后的内容,不会对原文件数据删除 -a 添加,a 的后面可以接字符串,该字符串会在当前指定行的下一行出现 -c 更改, c 的后面可以接字符串,该字符串可以取代 n1,n2 之间的行 -i 插入, i 的后面可以接

  • Python一键安装全部依赖包的方法

    requirements.txt用来记录项目所有的依赖包和版本号,只需要一个简单的pip命令就能完成. pip freeze >requirements.txt 然后就可以用 pip install -r requirements.txt 来一次性安装requirements.txt里面所有的依赖包,真是非常方便. 但是我最近发现了一个全新的Python包管理器,叫做pipenv,集合了所有编程语言的包管理器的优点,是kennethreitz大神的一个周末项目.它的工作方式就像Node.js里的

  • Apache下通过shell脚本提交网站404死链的方法

    网站运营人员对于死链这个概念一定不陌生,网站的一些数据删除或页面改版等都容易制造死链,影响用户体验不说,过多的死链还会影响到网站的整体权重或排名. 百度站长平台提供的死链提交工具,可将网站存在的死链(协议死链.404页面)进行提交,可快速删除死链,帮助网站SEO优化.在提交死链的文件中逐个手动填写死链的话太麻烦,工作中我们提倡复杂自动化,所以本文我们一起交流分享Apache服务中通过shell脚本整理网站死链,便于我们提交. . 1.配置Apache记录搜索引擎 Apache是目前网站建设最为主

随机推荐