Skip to content

一键安装mysql-5.7二进制包脚本

实战:centos7/centos8 一键安装mysql-5.7二进制包脚本(mysql-5.7.29)(测试成功)

image-20240417092809460

目录

[toc]

适用环境

bash
mysql-5.7.29
centos7.6 1810

或者
mysql-5.7.29
centos 8.1.1911

此脚本在以上2个环境里均测试成功。

1、脚本

脚本测试成功,可一键部署。

脚本来源:LaoWang from magedu。

链接:https://pan.baidu.com/s/199YdkWnhBMKDUHcYUeEKSw?pwd=hems 提取码:hems

2024.4.6-实战:通用二进制格式安装 MySQL(mysql-5.7.29)-2024.4.6(测试成功)

image-20240925073254711

  • 脚本内容

mysql5.7.29_install.sh

bash
#!/bin/bash

#MySQL5.7 Download URL: https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
. /etc/init.d/functions 
SRC_DIR=`pwd`
MYSQL='mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz'
COLOR='echo -e \E[01;31m'
END='\E[0m'
MYSQL_ROOT_PASSWORD=magedu

check (){
if [ $UID -ne 0 ]; then
 action "当前用户不是root,安装失败" false
 exit 1
fi


cd $SRC_DIR
if [ ! -e $MYSQL ];then
    $COLOR"缺少${MYSQL}文件"$END
 	    $COLOR"请将相关软件放在${SRC_DIR}目录下"$END
    exit
elif [ -e /usr/local/mysql ];then
    action "数据库已存在,安装失败" false
    exit
else
 return
fi
}


install_mysql(){
  $COLOR"开始安装MySQL数据库..."$END
    yum -y -q install libaio numactl-libs  libaio &> /dev/null
  cd $SRC_DIR
  tar xf $MYSQL -C /usr/local/
  MYSQL_DIR=`echo $MYSQL| sed -nr 's/^(.*[0-9]).*/\1/p'`
  ln -s /usr/local/$MYSQL_DIR /usr/local/mysql
  chown -R root.root /usr/local/mysql/
  id mysql &> /dev/null || { useradd -s /sbin/nologin -r mysql ; action "创建mysql用户"; }
    
  echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
   . /etc/profile.d/mysql.sh
  cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock                          
                        
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF

   mkdir -p /data/mysql
   chown mysql:mysql /data/mysql
  mysqld --initialize --user=mysql --datadir=/data/mysql 
  cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  chkconfig --add mysqld
  chkconfig mysqld on
  service mysqld start
  [ $? -ne 0 ] && { $COLOR"数据库启动失败,退出!"$END;exit; }
  MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
  mysqladmin -uroot -p$MYSQL_OLDPASSWORD password $MYSQL_ROOT_PASSWORD &>/dev/null
  action "数据库安装完成"
}

check

install_mysql

2、部署

把安装包、脚本传到linux机器,一键执行脚本即可。

  • 测试效果(符合预期)

image-20240417082838445

3、验证

刚安装完成后会是如下现象,重新打开一个终端就好:

image-20240925074924341

bash
[root@vm-template ~]#netstat -antlp|grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      17705/mysqld        
[root@vm-template ~]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> \q
Bye
[root@vm-template ~]#

注意

如果操作系统是centos 8.1.1911,则部署完成后,必须执行如下命令,否则会报错的。

image-20240925075249186

image-20240925075653224

解决办法:

bash
ln -s /lib64/libncurses.so.6.1 /lib64/libncurses.so.5
ln -s  /lib64/libtinfo.so.6.1 /lib64/libtinfo.so.5

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码

x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号

《云原生架构师实战》

image-20230107215126971

🍀 个人主页:

https://onedayxyy.cn

image-20240805214647028

🍀 知识库:

https://wiki.onedayxyy.cn/

🍀 博客:

http://blog.onedayxyy.cn/

image-20240804075845906

🍀 csdn

https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎

https://www.zhihu.com/people/foryouone

image-20230107215203185

往期推荐

QQ群

玩转Typora+Docusuaurus+起始页交流群:(欢迎小伙伴一起探讨有趣的IT技术,来完成一些漂亮的项目)

我的开源项目:

项目名称我的文档我的demo作者demo
1、玩转Typorahttps://wiki.onedayxyy.cn/docs/typorahttps://wiki.onedayxyy.cn/docs/typorahttps://typoraio.cn/#
2、玩转Docusaurushttps://wiki.onedayxyy.cn/docs/mogai-docusaurushttps://wiki.onedayxyy.cn/https://www.docusaurus.cn/
3、个人主页home3.0https://wiki.onedayxyy.cn/docs/home3.0https://onedayxyy.cn/https://github.com/hsBUPT/hsBUPT.github.io
4、全网最美博客-ruyu-bloghttps://wiki.onedayxyy.cn/docs/ruyu-blog-install-one-keyhttps://blog.onedayxyy.cn/https://www.kuailemao.xyz/
5、家庭相册filesite-iohttps://wiki.onedayxyy.cn/docs/filesite.io-photot-install-fullhttps://photo.onedayxyy.cn/https://demo.jialuoma.cn/

https://wiki.onedayxyy.cn/docs/OpenSource

image-20240811063938529

  • typora皮肤

https://wiki.onedayxyy.cn/docs/typora

image-20240518165037517

  • 起始页

https://onedayxyy.cn/

image-20240814230557697

  • 知识库

https://wiki.onedayxyy.cn/

  • 博客

https://blog.onedayxyy.cn/

image-20240803162010305

  • 家庭相册

https://photo.onedayxyy.cn/

image-20240923064332963

最后

好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!

最近更新