Centos 7下mysql 8.0.11的rpm包的安装方式

时间:2021-02-25 09:59:09

1.系统版本及mysql下载地址

操作系统:Centos 7.4

mysql数据库版本:mysql8.0.11

mysql官方网站:http://www.mysql.com

2.安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载

[bigdata@eric011 software-package]$ rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[bigdata@eric011 software-package]$ sudo rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

3.到mysql的官网下载最新版mysql的rpm集合包:mysql-8.0.11-1.el7.x86_64.rpm-bundle.tar

4.上传mysql-8.0.11-1.el7.x86_64.rpm-bundle.tar到linux服务器,并解压tar包

[bigdata@eric011 mysql]$ ls
mysql-community-client-8.0.11-1.el7.x86_64.rpm           mysql-community-libs-8.0.11-1.el7.x86_64.rpm               mysql-community-server-minimal-8.0.11-1.el7.x86_64.rpm
mysql-community-common-8.0.11-1.el7.x86_64.rpm           mysql-community-libs-compat-8.0.11-1.el7.x86_64.rpm        mysql-community-test-8.0.11-1.el7.x86_64.rpm
mysql-community-devel-8.0.11-1.el7.x86_64.rpm            mysql-community-minimal-debuginfo-8.0.11-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.11-1.el7.x86_64.rpm  mysql-community-server-8.0.11-1.el7.x86_64.rpm

5.其中最简单的安装mysql-server服务,只需要安装如下4个软件包即可,我们可以使用rpm -ivh命令进行安装

sudo rpm -ivh mysql-community-common-8.0.11-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-8.0.11-1.el7.x86_64.rpm --(依赖于common)
sudo rpm -ivh mysql-community-client-8.0.11-1.el7.x86_64.rpm --(依赖于libs)
sudo rpm -ivh mysql-community-server-8.0.11-1.el7.x86_64.rpm --(依赖于client、common)

注意:这一步可能遇到报错

[bigdata@eric011 mysql]$ sudo rpm -ivh mysql-community-server-8.0.11-1.el7.x86_64.rpm 
警告:mysql-community-server-8.0.11-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
	libaio.so.1()(64bit) 被 mysql-community-server-8.0.11-1.el7.x86_64 需要
	libaio.so.1(LIBAIO_0.1)(64bit) 被 mysql-community-server-8.0.11-1.el7.x86_64 需要
	libaio.so.1(LIBAIO_0.4)(64bit) 被 mysql-community-server-8.0.11-1.el7.x86_64 需要

解决方法:yum install libaio

6.初始化mysql数据库

[bigdata@eric011 mysql]$ sudo mysqld --initialize  //该命令会在/var/log/mysqld.log生成随机密码

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

[bigdata@eric011 lib]$ sudo chown mysql:mysql /var/lib/mysql -R
[bigdata@eric011 lib]$ systemctl start mysqld.service

8.根据第6步中的密码,更改root用户的密码,新版的mysql必须先修改root用户的密码,否则登录后是不能执行任何命令的

[bigdata@eric011 lib]$ mysql_secure_installation  //根据提示修改root用户密码

9.安装完成,接下来既可以正常操作mysql

[bigdata@eric011 lib]$ mysql -uroot -pxxxx
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 13
Server version: 8.0.11 MySQL Community Server - GPL

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> exit
版权声明:本文为博主原创文章,转载请注明出处!