本文主要针对初学者介绍如何在 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/4347 CSDN :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 来执行。
如上图,选择合适自己操作系统的 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 -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 97G 94G 3.9G 97% / devtmpfs 5.8G 0 5.8G 0% /dev tmpfs 5.8G 0 5.8G 0% /dev/shm tmpfs 5.8G 29M 5.8G 1% /run tmpfs 5.8G 0 5.8G 0% /sys/fs/cgroup /dev/sda1 1014M 180M 835M 18% /boot tmpfs 1.2G 0 1.2G 0% /run/user/1004 tmpfs 1.2G 4.0K 1.2G 1% /run/user/42 tmpfs 1.2G 56K 1.2G 1% /run/user/0 [root@JiekeXu yum.repos.d]# free -h total used free shared buff/cache available Mem: 11G 3.2G 285M 2.2G 8.1G 6.0G Swap: 2.0G 0B 2.0G [root@JiekeXu ~]# ping www.baidu.com PING 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 ms 64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=2 ttl=128 time=5.96 ms 64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=3 ttl=128 time=5.91 ms 64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=4 ttl=128 time=6.03 ms 64 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 4004ms rtt 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.rpm Loaded plugins: fastestmirror, langpacks Examining mysql80-community-release-el7-11.noarch.rpm: mysql80-community-release-el7-11.noarch Marking mysql80-community-release-el7-11.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql80-community-release.noarch 0:el7-11 will be installed --> Finished Dependency Resolution file:///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 k Installed size: 17 k Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running 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 234 mysql-tools-community/x86_64 MySQL Tools Community 102 mysql80-community/x86_64 MySQL 8.0 Community Server 446 [root@JiekeXu ~]# yum repolist all | grep mysql file:///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 disabled mysql-cluster-7.5-community-source MySQL Cluste disabled mysql-cluster-7.6-community/x86_64 MySQL Cluste disabled mysql-cluster-7.6-community-source MySQL Cluste disabled mysql-cluster-8.0-community/x86_64 MySQL Cluste disabled mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluste disabled mysql-cluster-8.0-community-source MySQL Cluste disabled mysql-cluster-innovation-community/x86_64 MySQL Cluste disabled mysql-cluster-innovation-community-debuginfo/x86_64 MySQL Cluste disabled mysql-cluster-innovation-community-source MySQL Cluste disabled mysql-connectors-community/x86_64 MySQL Connec enabled: 234 mysql-connectors-community-debuginfo/x86_64 MySQL Connec disabled mysql-connectors-community-source MySQL Connec disabled mysql-innovation-community/x86_64 MySQL Innova disabled mysql-innovation-community-debuginfo/x86_64 MySQL Innova disabled mysql-innovation-community-source MySQL Innova disabled mysql-tools-community/x86_64 MySQL Tools enabled: 102 mysql-tools-community-debuginfo/x86_64 MySQL Tools disabled mysql-tools-community-source MySQL Tools disabled mysql-tools-innovation-community/x86_64 MySQL Tools disabled mysql-tools-innovation-community-debuginfo/x86_64 MySQL Tools disabled mysql-tools-innovation-community-source MySQL Tools disabled mysql-tools-preview/x86_64 MySQL Tools disabled mysql-tools-preview-source MySQL Tools disabled mysql57-community/x86_64 MySQL 5.7 Co disabled mysql57-community-source MySQL 5.7 Co disabled mysql80-community/x86_64 MySQL 8.0 Co enabled: 446 mysql80-community-debuginfo/x86_64 MySQL 8.0 Co disabled mysql80-community-source MySQL 8.0 Co disabled
复制
要安装最新GA系列的最新版本,不需要进行任何配置。要安装非最新GA系列的特定系列的最新版本,请在运行安装命令之前禁用最新GA系列的子存储库,并启用特定系列的子存储库。如果您的平台支持yum-config-manager,您可以通过发出以下命令来实现,这些命令将禁用5.7系列的子存储库并启用8.0系列的子存储库:
[root@JiekeXu ~]# yum-config-manager --disable mysql57-community Loaded plugins: fastestmirror, langpacks =================================================== repo: mysql57-community =================================================== [mysql57-community] async = True bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7 baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64 cache = 0 cachedir = /var/cache/yum/x86_64/7/mysql57-community check_config_file_age = True compare_providers_priority = 80 cost = 1000 deltarpm_metadata_percentage = 100 deltarpm_percentage = enabled = False enablegroups = True exclude = failovermethod = priority ftp_disable_epsv = False gpgcadir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgcadir gpgcakey = gpgcheck = True gpgdir = /var/lib/yum/repos/x86_64/7/mysql57-community/gpgdir gpgkey = 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 hdrdir = /var/cache/yum/x86_64/7/mysql57-community/headers http_caching = all includepkgs = ip_resolve = keepalive = True keepcache = False mddownloadpolicy = sqlite mdpolicy = group:small mediaid = metadata_expire = 21600 metadata_expire_filter = read-only:present metalink = minrate = 0 mirrorlist = mirrorlist_expire = 86400 name = MySQL 5.7 Community Server old_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/mysql57-community pkgdir = /var/cache/yum/x86_64/7/mysql57-community/packages proxy = False proxy_dict = proxy_password = proxy_username = repo_gpgcheck = False retries = 10 skip_if_unavailable = False ssl_check_cert_permissions = True sslcacert = sslclientcert = sslclientkey = sslverify = True throttle = 0 timeout = 30.0 ui_id = mysql57-community/x86_64 ui_repoid_vars = releasever, basearch username = [root@JiekeXu ~]# yum-config-manager --enable mysql80-community Loaded plugins: fastestmirror, langpacks =================================================== repo: mysql80-community =================================================== [mysql80-community] async = True bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7 baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64 cache = 0 cachedir = /var/cache/yum/x86_64/7/mysql80-community check_config_file_age = True compare_providers_priority = 80 cost = 1000 deltarpm_metadata_percentage = 100 deltarpm_percentage = enabled = True enablegroups = True exclude = failovermethod = priority ftp_disable_epsv = False gpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadir gpgcakey = gpgcheck = True gpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdir gpgkey = 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 hdrdir = /var/cache/yum/x86_64/7/mysql80-community/headers http_caching = all includepkgs = ip_resolve = keepalive = True keepcache = False mddownloadpolicy = sqlite mdpolicy = group:small mediaid = metadata_expire = 21600 metadata_expire_filter = read-only:present metalink = minrate = 0 mirrorlist = mirrorlist_expire = 86400 name = MySQL 8.0 Community Server old_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/mysql80-community pkgdir = /var/cache/yum/x86_64/7/mysql80-community/packages proxy = False proxy_dict = proxy_password = proxy_username = repo_gpgcheck = False retries = 10 skip_if_unavailable = False ssl_check_cert_permissions = True sslcacert = sslclientcert = sslclientkey = sslverify = True throttle = 0 timeout = 30.0 ui_id = mysql80-community/x86_64 ui_repoid_vars = releasever, basearch username =
复制
除了使用 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 Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch enabled=1 gpgcheck=1 gpgkey=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 Server baseurl=http://repo.mysql.com/yum/mysql-innovation-community/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch enabled=1 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch enabled=1 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-tools-innovation-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=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 Preview baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-innovation-community/el/7/$basearch enabled=0 gpgcheck=1 gpgkey=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 mysql 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 234 mysql-tools-community/x86_64 MySQL Tools Community 102 mysql80-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 mysql Loaded plugins: fastestmirror, langpacks No such command: module. Please use /usr/bin/yum --help [root@JiekeXu ~]#
复制
5、安装 MySQL8.0.35
2024-01-16 MySQL8.0.36 正式发布了,现在应该可以安装 MySQL8.0.36 了,我这里还是安装 35 版本。
[root@JiekeXu ~]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.ustc.edu.cn * extras: mirrors.ustc.edu.cn * updates: mirrors.ustc.edu.cn file:///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_5 Installing 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 M Updating 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 M Total download size: 89 M Is this ok [y/d/N]: y Downloading 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: NOKEY Public 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-2023 Importing GPG key 0xA8D3785C: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" 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-2023 Is this ok [y/N]: y Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 Importing GPG key 0x3A79BD29: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" 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-2022 Is this ok [y/N]: y Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" 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-mysql Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running 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.log 2024-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 -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> 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.0 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 9 Server 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 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.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 测试题
For which installation method must you create the data directory manually? a. Binary Archive installation for Linux b. DEB installation for Linux c. MySQL Installer for Windows d. RPM installation for Linux Answer:a Choose the best answer. Where is the default data directory located after installing MySQL using RPM on Oracle Linux 7? A) /usr B) /usr/mysql C) /etc/my.cnf D) /var/1ib/mysql E) /usr/bin Answer: D /var/lib/mysql 更多题库解析请添加我个人微信获取,非商业用途,一起交流学习,否则追究法律责任后果自负。
复制
参考链接
https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
复制
————————————————————————————
微信公众号:JiekeXu DBA之路
墨天轮:https://www.modb.pro/u/4347
CSDN :https://blog.csdn.net/JiekeXu
腾讯云:https://cloud.tencent.com/developer/user/5645107
————————————————————————————