此文参考我前面的文章《在CentOS上用yum方式安装MySQL8过程记录》,之前比较曲折,现在再安装一台mysql。
因为之前很多坑已经走过,加上这台Linux之前没安装过MYSQL,所以整个过程算是非常顺利。
安装环境:centos7
mysql版本:8.0.35
过程中使用过的命令
#查看CentOS版本
[root@localhost ~]# cat /etc/centos-release
#查看是否安装了其它版本的mysql
[root@localhost ~]# rpm -qa | grep mysql
#安装MYSQL8的yum源
[root@localhost ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
#列出已启用的软件包仓库
[root@localhost ~]# yum repolist enabled
#过滤出包含 “mysql.-community.” 关键字的软件包仓库。
[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
[root@localhost ~]# yum repolist all | grep mysql
[root@localhost ~]# yum repolist all | grep "启用"
#安装Mysql
[root@localhost ~]# yum install mysql-community-server
#启动mysqld
[root@localhost ~]# systemctl start mysqld
#查看mysqld状态
[root@localhost ~]# systemctl status mysqld
#获取临时密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
#登录mysql
[root@localhost ~]# mysql -u root -p
mysql> use mysql;
#允许所有主机访问
mysql> update user set host = '%' where user = 'root';
mysql> FLUSH PRIVILEGES;
#修改密码和密码规则
mysql> alter user root@'%' identified with mysql_native_password by 'New*Password5';
mysql> FLUSH PRIVILEGES;
#查看密码
mysql> select Host,User,Plugin from mysql.user;
#防火墙放开端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --reload
真实操作记录
(为方便理解,以下为完整过程 )
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# rpm -qa | grep mysql
[root@localhost ~]#
[root@localhost ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
已加载插件:fastestmirror, langpacks
mysql80-community-release-el7-11.noarch.rpm | 14 kB 00:00:00
正在检查 /var/tmp/yum-root-IkD3oV/mysql80-community-release-el7-11.noarch.rpm: mysql80-community-release-el7-11.noarch
/var/tmp/yum-root-IkD3oV/mysql80-community-release-el7-11.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql80-community-release.noarch.0.el7-11 将被 安装
--> 解决依赖关系完成
依赖关系解决
===============================================================================================================================================================================================
Package 架构 版本 源 大小
===============================================================================================================================================================================================
正在安装:
mysql80-community-release noarch el7-11 /mysql80-community-release-el7-11.noarch 17 k
事务概要
===============================================================================================================================================================================================
安装 1 软件包
总计:17 k
安装大小:17 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql80-community-release-el7-11.noarch 1/1
验证中 : mysql80-community-release-el7-11.noarch 1/1
已安装:
mysql80-community-release.noarch 0:el7-11
完毕!
[root@localhost ~]# yum repolist enabled
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base 10,072
docker-ce-stable/7/x86_64 Docker CE Stable - x86_64 267
extras/7/x86_64 CentOS-7 - Extras 518
mysql-connectors-community/x86_64 MySQL Connectors Community 234
mysql-tools-community/x86_64 MySQL Tools Community 102
mysql80-community/x86_64 MySQL 8.0 Community Server 446
updates/7/x86_64 CentOS-7 - Updates 5,367
repolist: 17,006
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 234
mysql-tools-community/x86_64 MySQL Tools Community 102
mysql80-community/x86_64 MySQL 8.0 Community Server 446
[root@localhost ~]#
[root@localhost ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7 禁用
mysql-cluster-7.5-community-source MySQL Cluster 7 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7 禁用
mysql-cluster-7.6-community-source MySQL Cluster 7 禁用
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8 禁用
mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8 禁用
mysql-cluster-8.0-community-source MySQL Cluster 8 禁用
mysql-cluster-innovation-community/x86_64 MySQL Cluster I 禁用
mysql-cluster-innovation-community-debuginfo/x86_64 MySQL Cluster I 禁用
mysql-cluster-innovation-community-source MySQL Cluster I 禁用
mysql-connectors-community/x86_64 MySQL Connector 启用: 234
mysql-connectors-community-debuginfo/x86_64 MySQL Connector 禁用
mysql-connectors-community-source MySQL Connector 禁用
mysql-innovation-community/x86_64 MySQL Innovatio 禁用
mysql-innovation-community-debuginfo/x86_64 MySQL Innovatio 禁用
mysql-innovation-community-source MySQL Innovatio 禁用
mysql-tools-community/x86_64 MySQL Tools Com 启用: 102
mysql-tools-community-debuginfo/x86_64 MySQL Tools Com 禁用
mysql-tools-community-source MySQL Tools Com 禁用
mysql-tools-innovation-community/x86_64 MySQL Tools Inn 禁用
mysql-tools-innovation-community-debuginfo/x86_64 MySQL Tools Inn 禁用
mysql-tools-innovation-community-source MySQL Tools Inn 禁用
mysql-tools-preview/x86_64 MySQL Tools Pre 禁用
mysql-tools-preview-source MySQL Tools Pre 禁用
mysql57-community/x86_64 MySQL 5.7 Commu 禁用
mysql57-community-source MySQL 5.7 Commu 禁用
mysql80-community/x86_64 MySQL 8.0 Commu 启用: 446
mysql80-community-debuginfo/x86_64 MySQL 8.0 Commu 禁用
mysql80-community-source MySQL 8.0 Commu 禁用
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# yum repolist all | grep "启用"
base/7/x86_64 CentOS-7 - Base 启用: 10,072
docker-ce-stable/7/x86_64 Docker CE Stabl 启用: 267
extras/7/x86_64 CentOS-7 - Extr 启用: 518
mysql-connectors-community/x86_64 MySQL Connector 启用: 234
mysql-tools-community/x86_64 MySQL Tools Com 启用: 102
mysql80-community/x86_64 MySQL 8.0 Commu 启用: 446
updates/7/x86_64 CentOS-7 - Upda 启用: 5,367
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# yum install mysql-community-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.8.0.35-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.35-1.el7,它被软件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-icu-data-files = 8.0.35-1.el7,它被软件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.11,它被软件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.8.0.35-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-client-plugins = 8.0.35-1.el7,它被软件包 mysql-community-client-8.0.35-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.11,它被软件包 mysql-community-client-8.0.35-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.8.0.35-1.el7 将被 安装
---> 软件包 mysql-community-icu-data-files.x86_64.0.8.0.35-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
---> 软件包 mysql-community-client-plugins.x86_64.0.8.0.35-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.8.0.35-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.35-1.el7 将被 舍弃
--> 解决依赖关系完成
依赖关系解决
===============================================================================================================================================================================================
Package 架构 版本 源 大小
===============================================================================================================================================================================================
正在安装:
mysql-community-libs x86_64 8.0.35-1.el7 mysql80-community 1.5 M
替换 mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 8.0.35-1.el7 mysql80-community 669 k
替换 mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 8.0.35-1.el7 mysql80-community 64 M
为依赖而安装:
mysql-community-client x86_64 8.0.35-1.el7 mysql80-community 16 M
mysql-community-client-plugins x86_64 8.0.35-1.el7 mysql80-community 3.5 M
mysql-community-common x86_64 8.0.35-1.el7 mysql80-community 665 k
mysql-community-icu-data-files x86_64 8.0.35-1.el7 mysql80-community 2.2 M
事务概要
===============================================================================================================================================================================================
安装 3 软件包 (+4 依赖软件包)
总下载量:89 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.35-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY ] 2.0 MB/s | 15 MB 00:00:37 ETA
mysql-community-client-8.0.35-1.el7.x86_64.rpm 的公钥尚未安装
(1/7): mysql-community-client-8.0.35-1.el7.x86_64.rpm | 16 MB 00:00:06
(2/7): mysql-community-common-8.0.35-1.el7.x86_64.rpm | 665 kB 00:00:00
(3/7): mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm | 2.2 MB 00:00:00
(4/7): mysql-community-libs-8.0.35-1.el7.x86_64.rpm | 1.5 MB 00:00:00
(5/7): mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm | 669 kB 00:00:00
(6/7): mysql-community-server-8.0.35-1.el7.x86_64.rpm | 64 MB 00:00:25
(7/7): mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm | 3.5 MB 00:01:19
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 1.1 MB/s | 89 MB 00:01:19
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023 检索密钥
导入 GPG key 0xA8D3785C:
用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指纹 : bca4 3417 c3b4 85dd 128e c6d4 b7b3 b788 a8d3 785c
软件包 : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
是否继续?[y/N]:y
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 检索密钥
导入 GPG key 0x3A79BD29:
用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指纹 : 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29
软件包 : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
是否继续?[y/N]:y
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指纹 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
软件包 : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-common-8.0.35-1.el7.x86_64 1/8
正在安装 : mysql-community-client-plugins-8.0.35-1.el7.x86_64 2/8
正在安装 : mysql-community-libs-8.0.35-1.el7.x86_64 3/8
正在安装 : mysql-community-client-8.0.35-1.el7.x86_64 4/8
正在安装 : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 5/8
正在安装 : mysql-community-server-8.0.35-1.el7.x86_64 6/8
正在安装 : mysql-community-libs-compat-8.0.35-1.el7.x86_64 7/8
正在删除 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
验证中 : mysql-community-client-plugins-8.0.35-1.el7.x86_64 1/8
验证中 : mysql-community-common-8.0.35-1.el7.x86_64 2/8
验证中 : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 3/8
验证中 : mysql-community-libs-8.0.35-1.el7.x86_64 4/8
验证中 : mysql-community-client-8.0.35-1.el7.x86_64 5/8
验证中 : mysql-community-libs-compat-8.0.35-1.el7.x86_64 6/8
验证中 : mysql-community-server-8.0.35-1.el7.x86_64 7/8
验证中 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
已安装:
mysql-community-libs.x86_64 0:8.0.35-1.el7 mysql-community-libs-compat.x86_64 0:8.0.35-1.el7 mysql-community-server.x86_64 0:8.0.35-1.el7
作为依赖被安装:
mysql-community-client.x86_64 0:8.0.35-1.el7 mysql-community-client-plugins.x86_64 0:8.0.35-1.el7 mysql-community-common.x86_64 0:8.0.35-1.el7
mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7
替代:
mariadb-libs.x86_64 1:5.5.68-1.el7
完毕!
[root@localhost ~]#
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@localhost ~]#
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]#
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2023-10-30 08:58:06 CST; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 103659 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 103738 (mysqld)
Status: "Server is operational"
Tasks: 38
Memory: 453.8M
CGroup: /system.slice/mysqld.service
└─103738 /usr/sbin/mysqld
10月 30 08:57:46 localhost.localdomain systemd[1]: Starting MySQL Server...
10月 30 08:58:06 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]#
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2023-10-30T00:57:54.496453Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >W2q!/MPH0Wu
[root@localhost ~]#
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.35
Copyright (c) 2000, 2023, 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.
mysql>
mysql> alter user root@'%' identified with mysql_native_password by 'New*Password5';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
#####备注:遇到一种情况是,必须先初始化密码先,否则会报:
# ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'Newpassword*';
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> use mysql;
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
# 这里必须先使前面生效,才能修改alter user root@'%',否则会报错:Operation ALTER USER failed for 'root'@'%'
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> alter user root@'%' identified with mysql_native_password by 'New*Password5';
Query OK, 0 rows affected (0.02 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> select Host,User,Plugin from mysql.user;
+-----------+------------------+-----------------------+
| Host | User | Plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.01 sec)
mysql>
mysql> exit
Bye
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-c
firewall-cmd firewall-config
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#
然后直接使用工具软件连接,一次成功!文章来源:https://www.toymoban.com/news/detail-731590.html
文章来源地址https://www.toymoban.com/news/detail-731590.html
到了这里,关于在CentOS上用yum方式安装MySQL8真实全过程记录(顺利版本)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!