Linux/Centos7 以 RPM 方式安装 mysql-5.7.23

本贴最后更新于 2132 天前,其中的信息可能已经沧海桑田

1.下载 mysql

官网地址:https://dev.mysql.com/downloads/

具体下载方式请看下图:

imagepng

imagepng

2.下载完成后,通过 ftp 上传到 centos

[root@eric111 software-package]# ls -al mysql*
-rw-r--r-- 1 root root 598528000 8月   6 20:23 mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar

3.解压

[root@eric111 software-package]# mkdir mysql5.7.23
[root@eric111 software-package]# tar xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar -C mysql5.7.23
mysql-community-common-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.23-1.el7.x86_64.rpm
mysql-community-server-5.7.23-1.el7.x86_64.rpm
mysql-community-devel-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-5.7.23-1.el7.x86_64.rpm
mysql-community-client-5.7.23-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.23-1.el7.x86_64.rpm
mysql-community-test-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.23-1.el7.x86_64.rpm
[root@eric111 software-package]# cd mysql5.7.23/
[root@eric111 mysql5.7.23]# ll
总用量 584508
-rw-r--r-- 1 7155 31415  25253600 6月  11 11:21 mysql-community-client-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    280860 6月  11 11:21 mysql-community-common-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3806132 6月  11 11:21 mysql-community-devel-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  46741768 6月  11 11:21 mysql-community-embedded-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  24079120 6月  11 11:21 mysql-community-embedded-compat-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 130014800 6月  11 11:21 mysql-community-embedded-devel-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2256452 6月  11 11:21 mysql-community-libs-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2116280 6月  11 11:21 mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  55898240 6月  11 11:21 mysql-community-minimal-debuginfo-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 173011196 6月  11 11:21 mysql-community-server-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  15279108 6月  11 11:21 mysql-community-server-minimal-5.7.23-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 119773428 6月  11 11:22 mysql-community-test-5.7.23-1.el7.x86_64.rpm

4.卸载掉 centos7 自带的 mariadb-lib

[root@eric111 mysql5.7.23]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@eric111 mysql5.7.23]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

5.这里我们只安装 mysql-server 服务,只需要安装如下 4 个软件包即可,使用 rpm -ivh 进行安装(按顺序安装,后面的服务依赖前面的服务)

mysql-community-common-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-5.7.23-1.el7.x86_64.rpm
mysql-community-client-5.7.23-1.el7.x86_64.rpm
mysql-community-server-5.7.23-1.el7.x86_64.rpm

具体如下:

[root@eric111 mysql5.7.23]# rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm 
警告:mysql-community-common-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.23-1.e################################# [100%]
[root@eric111 mysql5.7.23]# rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm 
警告:mysql-community-libs-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.23-1.el7################################# [100%]
[root@eric111 mysql5.7.23]# rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm 
警告:mysql-community-client-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.23-1.e################################# [100%]
[root@eric111 mysql5.7.23]# rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.23-1.e################################# [100%]

6.初始化数据库

[root@eric111 mysql5.7.23]# mysqld --initialize #初始化后会在/var/log/mysqld.log生成随机密码

7.修改 mysql 数据库目录的所属用户及其所属组,然后启动 mysql 数据库

[root@eric111 lib]# chown mysql:mysql /var/lib/mysql -R
[root@eric111 lib]# systemctl start mysqld.service
[root@eric111 lib]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2018-08-06 20:41:25 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 13031 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 13003 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 13034 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─13034 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
>
8月 06 20:41:22 eric111 systemd[1]: Starting MySQL Server...
8月 06 20:41:25 eric111 systemd[1]: Started MySQL Server.

注意:mysql5.7.23 安装后已默认设置为开机启动,如果没有设置,可以使用下面命令设置为开机启动

systemctl enable mysqld.service

8.登录 mysql,并修改 root 用户的密码(系统强制要求,否则不能操作 mysql)

[root@eric111 lib]# mysql -uroot -p'PCc08th_IDqh'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23
>
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
>
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.
>
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

9.可能会遇到的问题(上次装 5.7.17 遇到过,这次没有遇到,可能之前我已经安装了相关依赖)

1).缺少libaio
[root@Eric002 mysql5.7]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
	libaio.so.1()(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
	libaio.so.1(LIBAIO_0.1)(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
	libaio.so.1(LIBAIO_0.4)(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
	net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
解决办法:
[root@Eric002 mysql5.7]# yum install libaio
2)缺少net-tools
[root@Eric002 mysql5.7]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
	net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
解决办法:
>
yum install net-tools

OK,搞定!!!

  • MySQL

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是最流行的关系型数据库管理系统之一。

    692 引用 • 535 回帖
  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖
  • 数据库

    据说 99% 的性能瓶颈都在数据库。

    343 引用 • 723 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...