centos7不联网脚本安装mysql8

https://dev.mysql.com/downloads/mysql/下载mysql社区版服务组件

centos7默认安装的postfix邮件服务依赖了mariadb-libs,mysql8 rpm安装时要求环境无mariadb,所以先卸载。
--deps表示操作前不检查依赖

shell> rpm -e mariadb-libs --nodeps

安装libaio

shell> rpm -ivh libaio-*.el7.x86_64.rpm

安装mysql相关组件

shell> rpm -ivh mysql-community-{server,client,common,libs}-*

安装完毕后,启动mysql

shell> systemctl start mysqld

这里启动mysql的原因是为了让mysql做一些初始化操作

  • 初始话mysql服务
  • 在data目录创建密钥和证书
  • 安装密码验证组件
  • 创建root@localhost超管账号,root的密码保存在/var/log/mysqld.log

启动后,我们可以先查看root的初始密码

shell> grep 'temporary password' /var/log/mysqld.log
2019-11-14T02:09:41.971916Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >D?1hfo5*hs-

通过以下命令可以直接获取密码

shell> grep 'temporary password' /var/log/mysqld.log | sed 's/^.*root@localhost: //g'
>D?1hfo5*hs-

修改root密码为GODLIKE@csdn2019
msql8不能直接在命令行上书写密码,所以我们先把密码写入配置文件,这样后面登陆mysql命令行就不需要再输入密码了

shell> cat >> /etc/my.cnf << EOF
[mysql]
user=root
password=">D?1hfo5*hs-"
EOF

shell> mysql  --connect-expired-password  -e "alter user 'root'@'localhost' identified by 'GODLIKE@csdn2019';"
shell> sed -i[back] 's/^password=.*$/password=\"GODLIKE@csdn2019\"/g' /etc/my.cnf

sed -i[back]表示先备份原文件

执行sql脚本

shell> mysql -uroot < something.sql

安装过程中会抛出警告

warning: mysql-community-server-*.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

这是因为rpm安装软件时会先校验软件包的签名,所以得导入公钥到RPM:

# 我们可以直接在网络环境下载5072E1F5公钥到gpg仓库
shell> gpg --recv-keys 5072E1F5
# 从gpg仓库将公钥导出为文件
shell> gpg --export -a 5072e1f5 > 5072e1f5.asc
# 导入公钥到RPM
shell> rpm --import 5072e1f5.asc

https://dev.mysql.com/doc/refman/8.0/en/linux-installation-rpm.html
https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html
https://dev.mysql.com/doc/refman/8.0/en/checking-rpm-signature.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值