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