MySQL安装

1、安装成功的步骤

# 获取rpm
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
# 直接安装
yum install -y  mysql-community-server
# 查看服务
systemctl status mysql

2、安装成功后续

# 安装成功后续
# 启动
systemctl start mysqld.service
# 查看状态
systemctl status mysqld.service
# 是否开机启动(默认自启动)
systemctl list-unit-files | grep enabled
# 开机自启动
systemctl enable mysqld

# 查看临时密码
grep "password" /var/log/mysqld.log
# 登录(使用上述临时密码)
mysql -uroot -p
# 密码要符合mysql8安全规则,否则修改不成功
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
# 创建用户
create user 'aiops'@'%' identified by '123456';
# 分配远程权限
grant all privileges on *.* to 'aiops'@'%' with grant option;
# 刷新上述权限
flush privileges;

# 默认配置文件
vim /etc/my.cnf

# 如果使用Navicat等客户端连接时报错:caching_sha2_password
# mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password
# 远程连接请将'localhost'换成'%'

# 更改加密方式
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
# 更新用户密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

3、踩坑指南

3.1 踩坑1

  • 最开始参考的Linux 安装 MySQL 8.0.26 超详细图文步骤这个,最后参考MySQL配置通过systemctl管理,可以使用service start mysqld进行启动,但是使用systemctl start mysqld的时候报错,SELinux is preventing /usr/lib/systemd/systemd from 'read;无奈删除重做
  • 参考其他文章彻底的删除掉MySQL后,使用yum安装【最开始就应该使用这种,因为服务器可以访问网络】
  • 需要单独删除之前创建的mysqld.service文件
  • 需要单独删除/etc/my.cnf文件

3.2 踩坑2

  • 问题1:使用yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm设置rpm源之后,执行 yum install mysql-community-server 报错
    错误信息
错误:
 问题: cannot install the best candidate for the job
  - nothing provides libcrypto.so.10()(64bit) needed by mysql-community-server-8.0.39-1.el7.x86_64
  - nothing provides libssl.so.10()(64bit) needed by mysql-community-server-8.0.39-1.el7.x86_64
  - nothing provides libcrypto.so.10(libcrypto.so.10)(64bit) needed by mysql-community-server-8.0.39-1.el7.x86_64
  - nothing provides libssl.so.10(libssl.so.10)(64bit) needed by mysql-community-server-8.0.39-1.el7.x86_64
  - nothing provides libcrypto.so.10(OPENSSL_1.0.2)(64bit) needed by mysql-community-server-8.0.39-1.el7.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
  • 解决:排查了很久是否由于基础文件缺少导致,最后发现是网络问题导致的,直接修改Center OS源,参考CentOS源帮助文档
  • 问题2:再次执行还是报错
    • 解决:sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm获得rpm

3.3 踩坑3

  • 问题:导入的密钥没有公钥,错误的公钥?
导入公钥成功
导入的密钥没有公钥,错误的公钥?
mysql-community-client-8.0.39-1.el8.x86_64.rpm 的公钥没有安装. 失败的软件包是:mysql-community-client-8.0.39-1.el8.x86_64
 GPG密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
mysql-community-client-plugins-8.0.39-1.el8.x86_64.rpm 的公钥没有安装. 失败的软件包是:mysql-community-client-plugins-8.0.3
 GPG密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
mysql-community-common-8.0.39-1.el8.x86_64.rpm 的公钥没有安装. 失败的软件包是:mysql-community-common-8.0.39-1.el8.x86_64
 GPG密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
mysql-community-icu-data-files-8.0.39-1.el8.x86_64.rpm 的公钥没有安装. 失败的软件包是:mysql-community-icu-data-files-8.0.3
 GPG密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
mysql-community-libs-8.0.39-1.el8.x86_64.rpm 的公钥没有安装. 失败的软件包是:mysql-community-libs-8.0.39-1.el8.x86_64
 GPG密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
mysql-community-server-8.0.39-1.el8.x86_64.rpm 的公钥没有安装. 失败的软件包是:mysql-community-server-8.0.39-1.el8.x86_64
yum clean packages
rpm --import https://repo.mysql.com/rpm-gpg-key-mysql-2023
yum install -y  mysql-community-server

posted on 2024-07-30 13:48  凋鱼  阅读(5)  评论(0编辑  收藏  举报

导航