Centos 7安装 mysql 5.7

环境说明

环境说明:
centos7

安装步骤

1. 下载社区版源安装

wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql57-community-release-el7-10.noarch.rpm

2. 检查mysql源是否安装成功

yum repolist enabled | grep "mysql.*-community.*"

# stdout
mysql-connectors-community/x86_64 MySQL Connectors Community                 230
mysql-tools-community/x86_64      MySQL Tools Community                      138
mysql57-community/x86_64          MySQL 5.7 Community Server                 564

3. 安装mysql server

yum install -y mysql-community-server

4. 创建数据目录

mkdir /data/mysql
chown -R mysql:mysql /data/mysql

5. 修改配置文件

主要修改datadir目录,及添加了字符集参数

cat etc/my.cnf|grep -v "^#"

[mysqld]
character-set-server=utf8
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

6. 启动mysql服务

systemctl start mysqld

7. 获取默认密码

grep 'temporary password' /var/log/mysqld.log

8. 登录并修改密码

mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zw2pp0xxxxx';

9. 调整密码强度

默认强度为Medium
在这里插入图片描述

改为Low,并设置长度限制

# 更改密码策略为LOW
set global validate_password_policy=0;
# 更改密码长度
set global validate_password_length=6;

安装问题

安装时rpm签名错误

yum install -y mysql-community-server
...
...
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-server-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.


 Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

原因: 没有单独的签名。RPM包具有内置GPG签名和MD5校验和。

解决方案:加载密钥,然后再次运行yum install -y mysql-community-server

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

安装冲突

Dependencies Resolved

=====================================================================================================================================================================================================
 Package                                                Arch                                   Version                                       Repository                                         Size
=====================================================================================================================================================================================================
Installing:
 mysql-community-server                                 x86_64                                 5.7.37-1.el7                                  mysql57-community                                 174 M
Installing for dependencies:
 mysql-community-client                                 x86_64                                 5.7.37-1.el7                                  mysql57-community                                  25 M
 mysql-community-common                                 x86_64                                 5.7.37-1.el7                                  mysql57-community                                 311 k
 mysql-community-libs                                   x86_64                                 5.7.37-1.el7                                  mysql57-community                                 2.4 M

Transaction Summary
=====================================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total size: 202 M
Installed size: 878 M
Downloading packages:
Running transaction check
Running transaction test



Transaction check error:
  file /usr/lib64/mysql/libmysqlclient.so.20 from install of mysql-community-libs-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-shared-57-5.7.26-29.1.el7.x86_64
  file /usr/bin/mysql from install of mysql-community-client-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-client-57-5.7.26-29.1.el7.x86_64
  file /usr/bin/mysql_config_editor from install of mysql-community-client-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-client-57-5.7.26-29.1.el7.x86_64
  file /usr/bin/mysqladmin from install of mysql-community-client-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-client-57-5.7.26-29.1.el7.x86_64
  file /usr/bin/mysqlbinlog from install of mysql-community-client-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-client-57-5.7.26-29.1.el7.x86_64
  file /usr/bin/mysqlcheck from install of mysql-community-client-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-client-57-5.7.26-29.1.el7.x86_64
  file /usr/bin/mysqldump from install of mysql-community-client-5.7.37-1.el7.x86_64 conflicts with file from package Percona-Server-client-57-5.7.26-29.1.el7.x86_64

解决方案:删除错误包

rpm -e Percona-Server-client-57-5.7.26-29.1.el7.x86_64
rpm -e Percona-Server-shared-57-5.7.26-29.1.el7.x86_64

参考资料

  1. https://blog.51cto.com/mofansheng/2646771
  2. https://stackoverflow.com/questions/71239450/gpg-keys-issue-while-installing-mysql-community-server
  3. https://cloud.tencent.com/developer/article/1342166
  4. https://www.modb.pro/db/50727
  5. https://www.jianshu.com/p/5779aa264840

猜你喜欢

转载自blog.csdn.net/moluzhui/article/details/123213039