Centos8上yum安装mysql8

Posted liujunjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos8上yum安装mysql8相关的知识,希望对你有一定的参考价值。

安装Yum Repository

[root@liujunjun ~]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
--2020-12-08 08:06:16--  https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.215.59.160
正在连接 repo.mysql.com (repo.mysql.com)|23.215.59.160|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:30388 (30K) [application/x-redhat-package-manager]
正在保存至: “mysql80-community-release-el8-1.noarch.rpm”

mysql80-community-release-el8-1.noarch.rp 100%[====================================================================================>]  29.68K   166KB/s  用时 0.2s    

2020-12-08 08:06:17 (166 KB/s) - 已保存 “mysql80-community-release-el8-1.noarch.rpm” [30388/30388])

使用rpm来安装MySQL

[root@liujunjun ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
警告:mysql80-community-release-el8-1.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql80-community-release-el8-1  ################################# [100%]

使用yum安装mysql服务

[root@liujunjun ~]# yum install mysql-server

启动服务

[root@liujunjun ~]# systemctl start mysqld
[root@liujunjun ~]# systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@liujunjun ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, 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> 

修改root密码

在MySQL 8.04前,执行:SET PASSWORD=PASSWORD(‘[新密码]’);但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。

修改密码为123456(密码可以设置为任意值):

mysql> user mysql;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near user mysql at line 1
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 123456;
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> 
[root@liujunjun ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, 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> 

 

以上是关于Centos8上yum安装mysql8的主要内容,如果未能解决你的问题,请参考以下文章

ECS 部署 MySQ(CentOS8 安装MySQL8)

Centos8安装MySql,完美解决

CentOS8 安装MySQL8.0

CentOS8下安装mysql8

centos8 安装 mysql8

CentOS8 安装 MySQL8.0(RPM)