使用 rpm 包安装 MySQL 8.0.35

作者 | JiekeXu
来源 |公众号 JiekeXu DBA之路(ID: JiekeXu_IT)
如需转载请联系授权 | (个人微信 ID:JiekeXu_DBA)

大家好,我是 JiekeXu,很高兴又和大家见面了,今天和大家一起来看看  使用 rpm 包安装 MySQL 8.0.35,欢迎点击上方蓝字“JiekeXu DBA之路”关注我的公众号,标星或置顶,更多干货第一时间到达!

目    录
    1、添加 MySQL Yum 存储库
    2、使用 yum 安装此 rpm 包
    3、选择发行系列
    4、禁用默认 MySQL 模块
    5、安装 MySQL8.0.35
    6、启动 MySQL
    7、查看 root 用户临时密码
    8、登录 MySQL 并修改密码
    9、修改密码
    10、简单查看及基础设置
    MySQL 8.0 OCP 测试题
    参考链接

本文主要针对初学者介绍如何在 Linux 系统上使用 rpm 包的方式安装一台单机版的 MySQL,之前也在 Win10 上安装过单机版的 MySQL8.0,有需要的也可以点击此处 Windows 10 环境下 MySQL 8.0.33 安装指南。MySQL8.0 OCP 考试中也有关于使用 rpm 安装 MySQL 相关的考题,如果有考试的同学,也可以注意一下其中的细节。首先这里你需要准备一台可以上网的 Linux 操作系统,CPU 内存、磁盘大小不限制。







————————————————————————————微信公众号:JiekeXu DBA之路墨天轮:https://www.modb.pro/u/4347CSDN :https://blog.csdn.net/JiekeXu腾讯云:https://cloud.tencent.com/developer/user/5645107————————————————————————————


按照以下步骤安装最新的 GA 版本的 MySQL 使用 MySQL Yum 存储库:

1、添加 MySQL Yum 存储库





First, add the MySQL Yum repository to your system’s repository list. This is a one-time operation, which can be performed by installing an RPM provided by MySQL. Follow these steps:Go to the Download MySQL Yum Repository page (https://dev.mysql.com/downloads/repo/yum/) in the MySQL Developer Zone.

首先,将 MySQL Yum 存储库添加到系统的存储库列表。这是一次性操作,可以是通过安装 MySQL 提供的 RPM 来执行。


https://dev.mysql.com/downloads/repo/yum/

如上图,选择合适自己操作系统的 rpm包,点击 Download,会出现 Login 登录页面,这里选择“No thanks, just start my download.”跳过登录直接下载。然后将下载后的 rpm 包“mysql80-community-release-el7-11.noarch.rpm” 上传到 Linux 服务器。





























[root@JiekeXu yum.repos.d]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@JiekeXu yum.repos.d]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   97G   94G  3.9G  97% /devtmpfs                 5.8G     0  5.8G   0% /devtmpfs                    5.8G     0  5.8G   0% /dev/shmtmpfs                    5.8G   29M  5.8G   1% /runtmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup/dev/sda1               1014M  180M  835M  18% /boottmpfs                    1.2G     0  1.2G   0% /run/user/1004tmpfs                    1.2G  4.0K  1.2G   1% /run/user/42tmpfs                    1.2G   56K  1.2G   1% /run/user/0[root@JiekeXu yum.repos.d]# free -h              total        used        free      shared  buff/cache   availableMem:            11G        3.2G        285M        2.2G        8.1G        6.0GSwap:          2.0G          0B        2.0G  [root@JiekeXu ~]# ping www.baidu.comPING www.a.shifen.com (220.181.38.149) 56(84) bytes of data.64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=1 ttl=128 time=5.81 ms64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=2 ttl=128 time=5.96 ms64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=3 ttl=128 time=5.91 ms64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=4 ttl=128 time=6.03 ms64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=5 ttl=128 time=5.16 ms^C--- www.a.shifen.com ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 4004msrtt min/avg/max/mdev = 5.169/5.778/6.031/0.327 ms


2、使用 yum 安装此 rpm 包







































[root@JiekeXu ~]# yum install mysql80-community-release-el7-11.noarch.rpmLoaded plugins: fastestmirror, langpacksExamining mysql80-community-release-el7-11.noarch.rpm: mysql80-community-release-el7-11.noarchMarking mysql80-community-release-el7-11.noarch.rpm to be installedResolving Dependencies--> Running transaction check---> Package mysql80-community-release.noarch 0:el7-11 will be installed--> Finished Dependency Resolutionfile:///mnt/centos/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/centos/repodata/repomd.xml"Trying other mirror.
Dependencies Resolved
=============================================================================================================================== Package                            Arch            Version            Repository                                         Size===============================================================================================================================Installing: mysql80-community-release          noarch          el7-11             /mysql80-community-release-el7-11.noarch           17 k
Transaction Summary===============================================================================================================================Install  1 Package
Total size: 17 kInstalled size: 17 kIs this ok [y/d/N]: yDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Installing : mysql80-community-release-el7-11.noarch                                                                     1/1  Verifying  : mysql80-community-release-el7-11.noarch                                                                     1/1
Installed:  mysql80-community-release.noarch 0:el7-11                                                                                    
Complete!


3、选择发行系列

在 MySQL Yum 存储库中,MySQL 社区服务器的不同版本系列托管在不同的子存储库中。最新 GA 系列(当前 MySQL 8.0 )的子存储库默认是启用的,而所有其他系列(例如MySQL 8.0 系列)的子存储库默认是禁用的。使用此命令查看 MySQL Yum 存储库中的所有子存储库,并查看其中哪些是启用或禁用的(对于启用 dnf 的系统,将命令中的 Yum 替换为 dnf ):








































[root@JiekeXu ~]# yum repolist enabled | grep "mysql.*-community.*"file:///mnt/centos/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/centos/repodata/repomd.xml"Trying other mirror.mysql-connectors-community/x86_64       MySQL Connectors Community           234mysql-tools-community/x86_64            MySQL Tools Community                102mysql80-community/x86_64                MySQL 8.0 Community Server           446[root@JiekeXu ~]# yum repolist all | grep mysqlfile:///mnt/centos/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/centos/repodata/repomd.xml"Trying other mirror.mysql-cluster-7.5-community/x86_64                  MySQL Cluste disabledmysql-cluster-7.5-community-source                  MySQL Cluste disabledmysql-cluster-7.6-community/x86_64                  MySQL Cluste disabledmysql-cluster-7.6-community-source                  MySQL Cluste disabledmysql-cluster-8.0-community/x86_64                  MySQL Cluste disabledmysql-cluster-8.0-community-debuginfo/x86_64        MySQL Cluste disabledmysql-cluster-8.0-community-source                  MySQL Cluste disabledmysql-cluster-innovation-community/x86_64           MySQL Cluste disabledmysql-cluster-innovation-community-debuginfo/x86_64 MySQL Cluste disabledmysql-cluster-innovation-community-source           MySQL Cluste disabledmysql-connectors-community/x86_64                   MySQL Connec enabled:    234mysql-connectors-community-debuginfo/x86_64         MySQL Connec disabledmysql-connectors-community-source                   MySQL Connec disabledmysql-innovation-community/x86_64                   MySQL Innova disabledmysql-innovation-community-debuginfo/x86_64         MySQL Innova disabledmysql-innovation-community-source                   MySQL Innova disabledmysql-tools-community/x86_64                        MySQL Tools  enabled:    102mysql-tools-community-debuginfo/x86_64              MySQL Tools  disabledmysql-tools-community-source                        MySQL Tools  disabledmysql-tools-innovation-community/x86_64             MySQL Tools  disabledmysql-tools-innovation-community-debuginfo/x86_64   MySQL Tools  disabledmysql-tools-innovation-community-source             MySQL Tools  disabledmysql-tools-preview/x86_64                          MySQL Tools  disabledmysql-tools-preview-source                          MySQL Tools  disabledmysql57-community/x86_64                            MySQL 5.7 Co disabledmysql57-community-source                            MySQL 5.7 Co disabledmysql80-community/x86_64                            MySQL 8.0 Co enabled:    446mysql80-community-debuginfo/x86_64                  MySQL 8.0 Co disabledmysql80-community-source                            MySQL 8.0 Co disabled

要安装最新GA系列的最新版本,不需要进行任何配置。要安装非最新GA系列的特定系列的最新版本,请在运行安装命令之前禁用最新GA系列的子存储库,并启用特定系列的子存储库。如果您的平台支持 yum-config-manager,您可以通过发出以下命令来实现,这些命令将禁用5.7系列的子存储库并启用8.0系列的子存储库:




































































































































[root@JiekeXu ~]# yum-config-manager --disable mysql57-communityLoaded plugins: fastestmirror, langpacks=================================================== repo: mysql57-community ===================================================[mysql57-community]async = Truebandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/7baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64cache = 0cachedir = /var/cache/yum/x86_64/7/mysql57-communitycheck_config_file_age = Truecompare_providers_priority = 80cost = 1000deltarpm_metadata_percentage = 100deltarpm_percentage = enabled = Falseenablegroups = Trueexclude = failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgcadirgpgcakey = gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgdirgpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023,   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlhdrdir = /var/cache/yum/x86_64/7/mysql57-community/headershttp_caching = allincludepkgs = ip_resolve = keepalive = Truekeepcache = Falsemddownloadpolicy = sqlitemdpolicy = group:smallmediaid = metadata_expire = 21600metadata_expire_filter = read-only:presentmetalink = minrate = 0mirrorlist = mirrorlist_expire = 86400name = MySQL 5.7 Community Serverold_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/mysql57-communitypkgdir = /var/cache/yum/x86_64/7/mysql57-community/packagesproxy = Falseproxy_dict = proxy_password = proxy_username = repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert = sslclientcert = sslclientkey = sslverify = Truethrottle = 0timeout = 30.0ui_id = mysql57-community/x86_64ui_repoid_vars = releasever,   basearchusername = 
[root@JiekeXu ~]# yum-config-manager --enable mysql80-communityLoaded plugins: fastestmirror, langpacks=================================================== repo: mysql80-community ===================================================[mysql80-community]async = Truebandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/7baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64cache = 0cachedir = /var/cache/yum/x86_64/7/mysql80-communitycheck_config_file_age = Truecompare_providers_priority = 80cost = 1000deltarpm_metadata_percentage = 100deltarpm_percentage = enabled = Trueenablegroups = Trueexclude = failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadirgpgcakey = gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdirgpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023,   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,   file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlhdrdir = /var/cache/yum/x86_64/7/mysql80-community/headershttp_caching = allincludepkgs = ip_resolve = keepalive = Truekeepcache = Falsemddownloadpolicy = sqlitemdpolicy = group:smallmediaid = metadata_expire = 21600metadata_expire_filter = read-only:presentmetalink = minrate = 0mirrorlist = mirrorlist_expire = 86400name = MySQL 8.0 Community Serverold_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/mysql80-communitypkgdir = /var/cache/yum/x86_64/7/mysql80-community/packagesproxy = Falseproxy_dict = proxy_password = proxy_username = repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert = sslclientcert = sslclientkey = sslverify = Truethrottle = 0timeout = 30.0ui_id = mysql80-community/x86_64ui_repoid_vars = releasever,   basearchusername =


除了使用 yum-config-manager 或 dnf config-manager 命令外,您还可以通过手动编辑 /etc/yum.rerepos.d/mysql-community.repo 文件来选择一个发布系列。这是一个典型的发布系列的子存储库在文件中的条目:












































































































[root@JiekeXu ~]# cat /etc/yum.repos.d/mysql-community.repo# Enable to use MySQL 5.7[mysql57-community]name=MySQL 5.7 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]name=MySQL 8.0 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearchenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-innovation-community]name=MySQL Innovation Release Community Serverbaseurl=http://repo.mysql.com/yum/mysql-innovation-community/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
[mysql-connectors-community]name=MySQL Connectors Communitybaseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearchenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]name=MySQL Tools Communitybaseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearchenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-innovation-community]name=MySQL Tools Innovation Communitybaseurl=http://repo.mysql.com/yum/mysql-tools-innovation-community/el/7/$basearch/enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
[mysql-tools-preview]name=MySQL Tools Previewbaseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.5-community]name=MySQL Cluster 7.5 Communitybaseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.6-community]name=MySQL Cluster 7.6 Communitybaseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-8.0-community]name=MySQL Cluster 8.0 Communitybaseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-innovation-community]name=MySQL Cluster Innovation Release Communitybaseurl=http://repo.mysql.com/yum/mysql-cluster-innovation-community/el/7/$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022[root@JiekeXu ~]#
[root@JiekeXu ~]# yum repolist enabled | grep mysqlfile:///mnt/centos/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/centos/repodata/repomd.xml"Trying other mirror.mysql-connectors-community/x86_64       MySQL Connectors Community           234mysql-tools-community/x86_64            MySQL Tools Community                102mysql80-community/x86_64                MySQL 8.0 Community Server           446[root@JiekeXu ~]#


4、禁用默认 MySQL 模块

(仅限 EL8 系统)基于 EL8 的系统(如 RHEL8 和 Oracle Linux 8)包含默认开启的 MySQL模块。除非该模块被禁用,否则它会屏蔽 MySQL 存储库提供的包。要禁用包含的模块并使 MySQL 存储库包可见,使用以下命令(对于启用 dnf 的系统,将命令中的 yum 替换为 dnf)。

注意:这里仅针对 Linux8 操作系统,如果是 Linux7 会和我这里一样报错。





[root@JiekeXu ~]# yum module disable mysqlLoaded plugins: fastestmirror, langpacksNo such command: module. Please use /usr/bin/yum --help[root@JiekeXu ~]#


5、安装 MySQL8.0.35

2024-01-16 MySQL8.0.36 正式发布了,现在应该可以安装 MySQL8.0.36 了,我这里还是安装 8.0.35 版本。




















































































































































































[root@JiekeXu ~]# yum install mysql-community-serverLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.ustc.edu.cn * extras: mirrors.ustc.edu.cn * updates: mirrors.ustc.edu.cnfile:///mnt/centos/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/centos/repodata/repomd.xml"Trying other mirror.Resolving Dependencies--> Running transaction check---> Package mariadb-server.x86_64 1:5.5.60-1.el7_5 will be obsoleted---> Package mysql-community-server.x86_64 0:8.0.35-1.el7 will be obsoleting--> Processing Dependency: mysql-community-common(x86-64) = 8.0.35-1.el7 for package: mysql-community-server-8.0.35-1.el7.x86_64--> Processing Dependency: mysql-community-icu-data-files = 8.0.35-1.el7 for package: mysql-community-server-8.0.35-1.el7.x86_64--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.35-1.el7.x86_64--> Running transaction check---> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be obsoleted---> Package mysql-community-client.x86_64 0:8.0.35-1.el7 will be obsoleting--> Processing Dependency: mysql-community-client-plugins = 8.0.35-1.el7 for package: mysql-community-client-8.0.35-1.el7.x86_64--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.35-1.el7.x86_64---> Package mysql-community-common.x86_64 0:8.0.35-1.el7 will be installed---> Package mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7 will be installed--> Running transaction check---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be obsoleted--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-37.el7.x86_64--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64---> Package mysql-community-client-plugins.x86_64 0:8.0.35-1.el7 will be installed---> Package mysql-community-libs.x86_64 0:8.0.35-1.el7 will be obsoleting--> Running transaction check---> Package mysql-community-libs-compat.x86_64 0:8.0.35-1.el7 will be obsoleting---> Package net-snmp.x86_64 1:5.7.2-37.el7 will be updated---> Package net-snmp.x86_64 1:5.7.2-49.el7_9.3 will be an update--> Processing Dependency: net-snmp-libs = 1:5.7.2-49.el7_9.3 for package: 1:net-snmp-5.7.2-49.el7_9.3.x86_64--> Processing Dependency: net-snmp-agent-libs = 1:5.7.2-49.el7_9.3 for package: 1:net-snmp-5.7.2-49.el7_9.3.x86_64---> Package postfix.x86_64 2:2.10.1-7.el7 will be updated---> Package postfix.x86_64 2:2.10.1-9.el7 will be an update--> Running transaction check---> Package net-snmp-agent-libs.x86_64 1:5.7.2-37.el7 will be updated---> Package net-snmp-agent-libs.x86_64 1:5.7.2-49.el7_9.3 will be an update---> Package net-snmp-libs.x86_64 1:5.7.2-37.el7 will be updated--> Processing Dependency: net-snmp-libs = 1:5.7.2-37.el7 for package: 1:net-snmp-utils-5.7.2-37.el7.x86_64---> Package net-snmp-libs.x86_64 1:5.7.2-49.el7_9.3 will be an update--> Running transaction check---> Package net-snmp-utils.x86_64 1:5.7.2-37.el7 will be updated---> Package net-snmp-utils.x86_64 1:5.7.2-49.el7_9.3 will be an update--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================== Package                                   Arch              Version                        Repository                    Size===============================================================================================================================Installing: mysql-community-client                    x86_64            8.0.35-1.el7                   mysql80-community             16 M     replacing  mariadb.x86_64 1:5.5.60-1.el7_5 mysql-community-libs                      x86_64            8.0.35-1.el7                   mysql80-community            1.5 M     replacing  mariadb-libs.x86_64 1:5.5.60-1.el7_5 mysql-community-libs-compat               x86_64            8.0.35-1.el7                   mysql80-community            669 k     replacing  mariadb-libs.x86_64 1:5.5.60-1.el7_5 mysql-community-server                    x86_64            8.0.35-1.el7                   mysql80-community             64 M     replacing  mariadb-server.x86_64 1:5.5.60-1.el7_5Installing for dependencies: 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 MUpdating for dependencies: net-snmp                                  x86_64            1:5.7.2-49.el7_9.3             updates                      325 k net-snmp-agent-libs                       x86_64            1:5.7.2-49.el7_9.3             updates                      707 k net-snmp-libs                             x86_64            1:5.7.2-49.el7_9.3             updates                      752 k net-snmp-utils                            x86_64            1:5.7.2-49.el7_9.3             updates                      201 k postfix                                   x86_64            2:2.10.1-9.el7                 base                         2.4 M
Transaction Summary===============================================================================================================================Install  4 Packages (+3 Dependent packages)Upgrade             ( 5 Dependent packages)
Total size: 93 MTotal download size: 89 MIs this ok [y/d/N]: yDownloading packages:warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEYPublic key for mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm is not installed(1/7): mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm                                           | 3.5 MB  00:00:03     (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:01     (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:11     (7/7): mysql-community-client-8.0.35-1.el7.x86_64.rpm                                                   |  16 MB  00:01:45     -------------------------------------------------------------------------------------------------------------------------------Total                                                                                          859 kB/s |  89 MB  00:01:45     Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023Importing GPG key 0xA8D3785C: Userid     : "MySQL Release Engineering " Fingerprint: bca4 3417 c3b4 85dd 128e c6d4 b7b3 b788 a8d3 785c Package    : mysql80-community-release-el7-11.noarch (installed) From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023Is this ok [y/N]: yRetrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022Importing GPG key 0x3A79BD29: Userid     : "MySQL Release Engineering " Fingerprint: 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29 Package    : mysql80-community-release-el7-11.noarch (installed) From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022Is this ok [y/N]: yRetrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlImporting GPG key 0x5072E1F5: Userid     : "MySQL Release Engineering " Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package    : mysql80-community-release-el7-11.noarch (installed) From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlIs this ok [y/N]: yRunning transaction checkRunning transaction testTransaction test succeededRunning transaction  Updating   : 1:net-snmp-libs-5.7.2-49.el7_9.3.x86_64                                                                    1/20  Installing : mysql-community-client-plugins-8.0.35-1.el7.x86_64                                                         2/20  Installing : mysql-community-common-8.0.35-1.el7.x86_64                                                                 3/20  Installing : mysql-community-libs-8.0.35-1.el7.x86_64                                                                   4/20  Installing : mysql-community-libs-compat-8.0.35-1.el7.x86_64                                                            5/20  Updating   : 1:net-snmp-agent-libs-5.7.2-49.el7_9.3.x86_64                                                              6/20  Installing : mysql-community-client-8.0.35-1.el7.x86_64                                                                 7/20  Installing : mysql-community-icu-data-files-8.0.35-1.el7.x86_64                                                         8/20  Installing : mysql-community-server-8.0.35-1.el7.x86_64                                                                 9/20  Updating   : 1:net-snmp-5.7.2-49.el7_9.3.x86_64                                                                        10/20  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                                                             11/20  Updating   : 1:net-snmp-utils-5.7.2-49.el7_9.3.x86_64                                                                  12/20  Cleanup    : 1:net-snmp-5.7.2-37.el7.x86_64                                                                            13/20  Erasing    : 1:mariadb-server-5.5.60-1.el7_5.x86_64                                                                    14/20  Erasing    : 1:mariadb-5.5.60-1.el7_5.x86_64                                                                           15/20  Cleanup    : 1:net-snmp-agent-libs-5.7.2-37.el7.x86_64                                                                 16/20  Cleanup    : 2:postfix-2.10.1-7.el7.x86_64                                                                             17/20  Cleanup    : 1:net-snmp-utils-5.7.2-37.el7.x86_64                                                                      18/20  Cleanup    : 1:net-snmp-libs-5.7.2-37.el7.x86_64                                                                       19/20  Erasing    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                      20/20  Verifying  : mysql-community-common-8.0.35-1.el7.x86_64                                                                 1/20  Verifying  : mysql-community-icu-data-files-8.0.35-1.el7.x86_64                                                         2/20  Verifying  : 1:net-snmp-utils-5.7.2-49.el7_9.3.x86_64                                                                   3/20  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                                              4/20  Verifying  : mysql-community-client-plugins-8.0.35-1.el7.x86_64                                                         5/20  Verifying  : mysql-community-libs-8.0.35-1.el7.x86_64                                                                   6/20  Verifying  : 1:net-snmp-libs-5.7.2-49.el7_9.3.x86_64                                                                    7/20  Verifying  : mysql-community-client-8.0.35-1.el7.x86_64                                                                 8/20  Verifying  : mysql-community-libs-compat-8.0.35-1.el7.x86_64                                                            9/20  Verifying  : mysql-community-server-8.0.35-1.el7.x86_64                                                                10/20  Verifying  : 1:net-snmp-agent-libs-5.7.2-49.el7_9.3.x86_64                                                             11/20  Verifying  : 1:net-snmp-5.7.2-49.el7_9.3.x86_64                                                                        12/20  Verifying  : 1:mariadb-server-5.5.60-1.el7_5.x86_64                                                                    13/20  Verifying  : 2:postfix-2.10.1-7.el7.x86_64                                                                             14/20  Verifying  : 1:net-snmp-libs-5.7.2-37.el7.x86_64                                                                       15/20  Verifying  : 1:mariadb-5.5.60-1.el7_5.x86_64                                                                           16/20  Verifying  : 1:net-snmp-5.7.2-37.el7.x86_64                                                                            17/20  Verifying  : 1:net-snmp-utils-5.7.2-37.el7.x86_64                                                                      18/20  Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                      19/20  Verifying  : 1:net-snmp-agent-libs-5.7.2-37.el7.x86_64                                                                 20/20
Installed:  mysql-community-client.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                mysql-community-server.x86_64 0:8.0.35-1.el7              
Dependency Installed:  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              
Dependency Updated:  net-snmp.x86_64 1:5.7.2-49.el7_9.3                          net-snmp-agent-libs.x86_64 1:5.7.2-49.el7_9.3                      net-snmp-libs.x86_64 1:5.7.2-49.el7_9.3                     net-snmp-utils.x86_64 1:5.7.2-49.el7_9.3                          postfix.x86_64 2:2.10.1-9.el7                              
Replaced:  mariadb.x86_64 1:5.5.60-1.el7_5       mariadb-libs.x86_64 1:5.5.60-1.el7_5       mariadb-server.x86_64 1:5.5.60-1.el7_5      
Complete![root@JiekeXu ~]#


这将安装 MySQL 服务器包(MySQL -community-server)和运行服务器所需的组件包,包括客户端包(MySQL -community-client),客户端和服务器的常见错误消息和字符集(MySQL -community-common),以及共享的客户端库(MySQL -community-libs)。

6、启动 MySQL

如果操作系统启用了 systemd,则应该使用标准的 systemctl (或者,带相反参数的service) 命令,如 stop、start、status 和 restart 来管理 MySQL 服务器服务。mysqld 服务默认是启用的,它在系统重启时启动。

所以这里可以使用 systemd 系统管理命令来管理 MySQL,不用过多的设置,它也是开机自启动的。


















[root@JiekeXu ~]# systemctl start mysqld[root@JiekeXu ~]# systemctl status mysqld mysqld.service - MySQL Server   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)   Active: active (running) since Tue 2024-01-09 23:38:44 CST; 8s ago     Docs: man:mysqld(8)           http://dev.mysql.com/doc/refman/en/using-systemd.html  Process: 58352 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 58436 (mysqld)   Status: "Server is operational"    Tasks: 38   CGroup: /system.slice/mysqld.service           └─58436 /usr/sbin/mysqld
Jan 09 23:38:38 JiekeXu systemd[1]: Starting MySQL Server...Jan 09 23:38:44 JiekeXu systemd[1]: Started MySQL Server.[root@JiekeXu ~]# service mysqld status


在服务器初始启动时,假设服务器的data目录为空,会发生以下情况:

  • 初始化服务器。

  • 在 data 目录下生成 SSL 证书和密钥文件。

  • 已安装并启用 Validate_password。

  • 创建一个超级用户帐户 ‘root’@'localhost。设置超级用户的密码并将其存储在错误日志文件中。

7、查看 root 用户临时密码

在 /var/log/mysqld.log 下查看 root 用户临时密码。




[root@JiekeXu ~]# sudo grep 'temporary password' /var/log/mysqld.log2024-01-09T15:38:40.363927Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: W*UD:uDDE15-

8、登录 MySQL 并修改密码

如果不修改这个临时密码,无法进行任何操作,就连“show databases;”都无法执行。


















[root@JiekeXu ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.35
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql>


9、修改密码

validate_password 插件默认已经安装了。validate_password 实现的默认密码策略要求:密码至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为 8 个字符
















ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL8.0';
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL8.0';Query OK, 0 rows affected (0.01 sec)
mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)


10、简单查看及基础设置

可以看到,默认开启了 binlog,数据目录基本都存放于 /var/lib/mysql/ 目录


























































[root@JiekeXu ~]# mysql -uroot -pMySQL8.0mysql: [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 9Server version: 8.0.35 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
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.00 sec)mysql> show variables like '%datadir%';+---------------+-----------------+| Variable_name | Value           |+---------------+-----------------+| datadir       | /var/lib/mysql/ |+---------------+-----------------+1 row in set (0.01 sec)mysql> show variables like '%log_bin%';+---------------------------------+-----------------------------+| Variable_name                   | Value                       |+---------------------------------+-----------------------------+| log_bin                         | ON                          || log_bin_basename                | /var/lib/mysql/binlog       || log_bin_index                   | /var/lib/mysql/binlog.index || log_bin_trust_function_creators | OFF                         || log_bin_use_v1_row_events       | OFF                         || sql_log_bin                     | ON                          |+---------------------------------+-----------------------------+6 rows in set (0.00 sec)mysql> select version();+-----------+| version() |+-----------+| 8.0.35    |+-----------+1 row in set (0.00 sec)mysql> select @@port;+--------+| @@port |+--------+|   3306 |+--------+1 row in set (0.00 sec)


创建一个 root@’%’ 的超级用户,给他所有权限,注意使用密码认证插件 “mysql_native_password” 方可远程登录。




create user root@'%' identified  with 'mysql_native_password' by 'MySQL8.0'; 
grant all  privileges on *.* to root@'%'  with grant option;


MySQL 8.0 OCP 测试题

























1)、For which installation method must you create the data directory manually?
a. Binary Archive installation for Linuxb. DEB installation for Linuxc. MySQL Installer for Windowsd. RPM installation for Linux
Answer:a

2)、Choose the best answer.Where is the default data directory located after installing MySQL using RPM on Oracle Linux 7?
A) /usrB) /usr/mysqlC) /etc/my.cnfD) /var/1ib/mysqlE) /usr/bin
Answer: D  /var/lib/mysql
更多题库解析请添加我个人微信获取或 https://www.modb.pro/doc/124799 下载,非商业用途,一起交流学习,否则追究法律责任后果自负。

参考链接



https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html

全文完,希望可以帮到正在阅读的你,如果觉得此文对你有帮助,可以分享给你身边的朋友,同事,你关心谁就分享给谁,一起学习共同进步~~~

欢迎关注我公众号【JiekeXu DBA之路】,第一时间一起学习新知识!以下四个地址可以找到我,其他地址均属于盗版侵权爬取我的文章,而且代码格式、图片等均有错乱,不方便阅读,欢迎来我公众号或者墨天轮地址关注我,第一时间收获最新消息。

欢迎关注我的公众号【JiekeXu DBA之路】,第一时间一起学习新知识!————————————————————————————
公众号:JiekeXu DBA之路
CSDN :https://blog.csdn.net/JiekeXu
墨天轮:https://www.modb.pro/u/4347
腾讯云:https://cloud.tencent.com/developer/user/5645107
————————————————————————————



分享几个数据库备份脚本

一文搞懂 Oracle 统计信息
我的 Oracle ACE 心路历程Oracle 主流版本不同架构下的静默安装指南关机重启导致 ASM 磁盘丢失数据库无法启动Oracle SQL 性能分析(SPA)原理与实战演练

Oracle 11g 升级到 19c 需要关注的几个问题

Windows 10 环境下 MySQL 8.0.33 安装指南

SQL 大全(四)|数据库迁移升级时常用 SQL 语句

OGG|使用 OGG19c 迁移 Oracle11g 到 19C(第二版)

Oracle 大数据量导出工具——sqluldr2 的安装与使用

从国产数据库调研报告中你都能了解哪些信息及我的总结建议

使用数据泵利用 rowid 分片导出导入 lob 大表及最佳实践

在归档模式下直接 rm dbf 数据文件并重启数据库还有救吗?

请使用浏览器的分享功能分享到微信等