当前位置: 首页 > article >正文

MySQL自动安装脚本8.0和5.0均可

准备工作:上传安装脚本和安装包到/soft目录或者其他空目录。

#!/bin/bash
echo "-----------------------------start  install--------------------------------------"
start_time=$(date +%s)
echo -e "input version,such as \e[31m8.0.27\e[0m"
read version
find / -name mysql | xargs rm -rf
port=$(netstat -antup|grep mysql|wc -l)
if [ $port != 0 ]
then echo "The MySQL process exists, please kill the process first"
ps -ef |grep mysqld
exit 1
fi
echo "--------Create the required directory and user, and upload the installation package-----------"
current_dir=$(pwd)
echo "current directory: $current_dir"
target_dir="/opt"
if [ ! -d "$target_dir" ]; then
    mkdir -p "$target_dir"
    echo "target directory: $target_dir"
fi
mv $current_dir/* $target_dir
echo "copy complete to $target_dir"
mkdir -p  /data/mysql
groupadd mysql
useradd -r -g mysql mysql
cd /opt/
tar -xvf mysql-$version-linux-glibc2.12-x86_64.tar.gz
mv mysql-$version-linux-glibc2.12-x86_64/  /usr/local/
cd /usr/local/
mv mysql-$version-linux-glibc2.12-x86_64/ mysql
chown -R mysql.mysql /usr/local/mysql/
echo "-----------Uninstall the existing MySQL components---------------"
yum list installed | grep mariadb
yum -y remove mariadb*
yum remove mariadb*
chown mysql:mysql -R /data/mysql
touch /etc/my.cnf
chmod 644 /etc/my.cnf
MYSQL_ROOT_PASSWORD=123456
cat <<EOF >/etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
server_id=1
port=3306
character-set-server=utf8
innodb_rollback_on_timeout = ON
character-set-server = utf8
collation-server=utf8_general_ci
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
max_connections=10000
sync_binlog=1
binlog_format=row
log-bin=mysql-bin
expire_logs_days=30
[mysql]
socket=/tmp/mysql.sock
default-character-set=utf8
[client]
EOF
echo "---------------Initialize Database--------------"
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
path=$(grep 'MYSQL_HOME' /etc/profile|wc -l)
if [ $path !=  0 ]
  then
    echo -e "\e[31m MYSQL_HOME  The path exists\e[0m"
  else
    echo "export MYSQL_HOME=/usr/local/mysql/bin" >> /etc/profile
    echo "export PATH=\$PATH:\$MYSQL_HOME"        >> /etc/profile
    source /etc/profile
fi
echo "-----------------------Start MYSQL service------------------------------"
service mysql start
echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib'>>/etc/profile
sleep 3
source /etc/profile
cat /data/mysql/mysql.err|grep password
chkconfig --add mysql
chkconfig mysql on
chkconfig --list mysql
echo "------------congratulations! MYSQL installation successful--------------"
end_time=$(date +%s)
execution_time=$((end_time - start_time))
echo "Script execution time:${execution_time} s"
MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.err`
mysqladmin  -uroot -p${MYSQL_OLDPASSWORD} password ${MYSQL_ROOT_PASSWORD}
mysql -uroot -p123456 -e "update mysql.user set host ='%' where user ='root';"
mysql -uroot -p123456 -e "flush privileges;"
mysql -uroot -p123456


注意事项:注意mysql安装包的名称格式,不同版本的安装包名称可能不通,注意修改脚本中安装包名称后缀。
1.根据安装包名称修改脚本中名称后缀

一个后缀是xz一个后缀是gz
mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz

2.安装开始之后输入版本号就行了
在这里插入图片描述
3.注意修改脚本中MYSQL_ROOT_PASSWORD作为mysql数据库密码


http://www.kler.cn/news/290843.html

相关文章:

  • SD-WAN组网:定义与部署步骤解析
  • AI绘画SD中如何安装/更新/卸载 Stable Diffusion WebUI 插件?SD新手必看的保姆级教程!
  • 使用 Cloudflare R2 代替 AWS S3……
  • Day15_0.1基础学习MATLAB学习小技巧总结(15)——字符矩阵
  • Python批量分割Excel后逐行做差、合并文件的方法
  • Redisson的几种锁的通俗说明
  • Go语言多态实践以及gin框架c.BindJSON序列化遇到的坑
  • C#数组中的Rank,GetUpperBound(), GetLength()
  • linux find 之 执行
  • GIT 下载安装使用教程
  • 小程序中用于跳转页面的5个api是什么?区别是什么
  • 【计算机网络】TCP协议
  • 【深度学习】向量化
  • 第 22 章 JavaScript DOM 元素尺寸和位置
  • Hadoop vs Spark
  • fpga图像处理实战-均值滤波
  • 从0开始学杂项 第八期:流量分析(2) 数据提取
  • Spring之整合Mybatis底层源码解析
  • 信息安全发展阶段与形式
  • 搜维尔科技:研究和使用Geomagic Touch X触觉反馈设备进行医疗模拟
  • 大数据Flink(一百一十二):Flink SQL作业快速入门
  • 【深度学习详解】Task3 实践方法论-分类任务实践 Datawhale X 李宏毅苹果书 AI夏令营
  • 第九届“创客中国”生成式人工智能中小企业创新创业大赛招商推介圆满落幕
  • Maven与Gradle差异
  • 突破教材,简单聊聊《文件系统》
  • 开源 AI 智能名片 O2O 商城小程序:引入淘汰机制,激发社交电商新活力
  • 电子设计-基础3-电感与二极管
  • 深入探讨MySQL的MVCC机制
  • QT5记录 QHBoxLayout ScrollArea导致QLabel重新计算位置导致内容显示不全
  • Hadoop 下载