最新版本:https://dev.mysql.com/downloads/mysql/
历史版本:https://downloads.mysql.com/archives/community/
官方安装文档:https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/linux-installation-rpm.html

Centos7使用RPM包安装MySQL5.7

卸载

查找系统已安装的MySQL或mariadb

rpm -qa | grep "mysql\|mariadb"

使用rpm -e 卸载旧的软件

rpm -e mariadb-libs-5.5.68-1.el7.x86_64

如果遇到error: Failed dependencies: libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64 libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64, 加上--nodeps即可, 表示不验证包依赖关系。

rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

安装

解压

# 解压
tar xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
# 目录结构
.
├── mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
├── mysql-community-client-5.7.35-1.el7.x86_64.rpm
├── mysql-community-common-5.7.35-1.el7.x86_64.rpm
├── mysql-community-devel-5.7.35-1.el7.x86_64.rpm
├── mysql-community-embedded-5.7.35-1.el7.x86_64.rpm
├── mysql-community-embedded-compat-5.7.35-1.el7.x86_64.rpm
├── mysql-community-embedded-devel-5.7.35-1.el7.x86_64.rpm
├── mysql-community-libs-5.7.35-1.el7.x86_64.rpm
├── mysql-community-libs-compat-5.7.35-1.el7.x86_64.rpm
├── mysql-community-server-5.7.35-1.el7.x86_64.rpm
└── mysql-community-test-5.7.35-1.el7.x86_64.rpm

标准安装只需依次安装:mysql-community-common mysql-community-libs mysql-community-client mysql-community-server

# common
 ➜  ~ rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.35-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.35-1.e################################# [100%]
# libs
 ➜  ~ mysql rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.35-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.35-1.el7################################# [100%]
# client
 ➜  ~ mysql rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.35-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.35-1.e################################# [100%]
# server
 ➜  ~ mysql rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.35-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.35-1.e################################# [100%]

初始化配置

启动服务

# 启动mysql服务,需要一段时间,请耐心等待
 ➜  ~ systemctl start mysqld.service
# 配置开机自启
 ➜  ~ systemctl enable mysqld.service

查看密码

 ➜  ~ grep 'password' /var/log/mysqld.log
2022-01-07T10:06:54.129349Z 1 [Note] A temporary password is generated for root@localhost: !b&rpw7Eqi!3

远程连接MySQL

 ➜  ~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.35

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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.
# 修改root密码(初次登陆密码必须修改)
mysql> alter user 'root'@'localhost' identified by '0#N2JtjauW4PWgAx';
Query OK, 0 rows affected (0.01 sec)
# 授权,允许所有主机通过root用户连接到MySQL
mysql> grant all privileges on *.* to 'root'@'%' identified by '0#N2JtjauW4PWgAx';
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 刷新权限,使授权立即生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
最后修改:2020 年 12 月 15 日
如果觉得我的文章对你有用,请随意赞赏