• 如何在Rocky Linux和AlmaLinux上安装MySQL 8.0


    用C语言编写,MySQL是一个开源,跨平台以及最广泛使用的关系型数据库管理系统(RDMS)之一。它是LAMP栈不可分割的部分并且是网站托管,数据分析和电子商务中流行的数据库管理系统。

    当前稳定发行是MySQL 8.0.25并且在2021年5月11日发布。最近发行的重点是:

    • InnoDB & XML增强
    • 事务数据字典
    • 对本地JSON数据和文档存储功能的增加支持
    • 公共表达式
    • 窗口函数
    • 诸如错误编号和减少冗余的错误日志增强

    以及更多,对于所有特性和增强的综合涵盖你可以检查发布注释。

    在本教程中,我们演示了如何在Rocky Linux和AlmaLinux上安装MySQL。

    第一步:更新Rocky Linux

    当我们安装软件包时,总是推荐从系统包更新开始。在某些情况下,升级内核时需要一次重启。因而,在命令行上,执行以下命令来更新内核和系统包:

    1. [root@localhost dbuser]# dnf update -y
    2. Last metadata expiration check: 0:13:15 ago on Tue 28 Jun 2022 04:05:16 PM CST.
    3. Dependencies resolved.
    4. =========================================================================================================================================================
    5. Package Architecture Version Repository Size
    6. =========================================================================================================================================================
    7. Upgrading:
    8. almalinux-release x86_64 8.6-2.el8
    9. ...
    10. Installed:
    11. grub2-tools-efi-1:2.02-123.el8_6.8.alma.x86_64
    12. Complete!
    13. [root@localhost dbuser]#

    第二步:启用MySQL上游模块

    继续前进,我们需要启用由AppStream仓库提供的MySQL 8.0模块。现在,这是被提供的唯一MySQL模块并且你能够通过运行以下命令验证这个:

    1. [root@localhost dbuser]# dnf module list mysql
    2. Last metadata expiration check: 0:28:50 ago on Tue 28 Jun 2022 04:05:16 PM CST.
    3. AlmaLinux 8 - AppStream
    4. Name Stream Profiles Summary
    5. mysql 8.0 [d] client, server [d] MySQL Module
    6. Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

    要启用MySQL模块srream,运行以下命令:

    1. Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
    2. [root@localhost dbuser]# dnf module enable mysql:8.0
    3. Last metadata expiration check: 0:30:05 ago on Tue 28 Jun 2022 04:05:16 PM CST.
    4. Dependencies resolved.
    5. =========================================================================================================================================================
    6. Package Architecture Version Repository Size
    7. =========================================================================================================================================================
    8. Enabling module streams:
    9. mysql 8.0
    10. Transaction Summary
    11. =========================================================================================================================================================
    12. Is this ok [y/N]: y
    13. Complete!

    第三步:在Rocky Linux上安装MySQL 8.0

    使能了这个模块,按如下在Rocky Linux上安装MySQL 8.0:

    1. [root@localhost dbuser]# dnf install @mysql
    2. Last metadata expiration check: 0:31:52 ago on Tue 28 Jun 2022 04:05:16 PM CST.
    3. Dependencies resolved.
    4. =========================================================================================================================================================
    5. Package Architecture Version Repository Size
    6. =========================================================================================================================================================
    7. Installing group/module packages:
    8. mysql-server x86_64 8.0.26-1.module_el8.4.0+2532+b8928c02 appstream 25 M
    9. Installing dependencies:
    10. mariadb-connector-c-config noarch 3.1.11-2.el8_3 appstream 14 k
    11. mecab x86_64 0.996-1.module_el8.4.0+2532+b8928c02.9 appstream 392 k
    12. mysql x86_64 8.0.26-1.module_el8.4.0+2532+b8928c02 appstream 12 M
    13. mysql-common x86_64 8.0.26-1.module_el8.4.0+2532+b8928c02 appstream 133 k
    14. mysql-errmsg x86_64 8.0.26-1.module_el8.4.0+2532+b8928c02 appstream 597 k
    15. protobuf-lite x86_64 3.5.0-13.el8 appstream 148 k
    16. Installing module profiles:
    17. mysql/server
    18. Transaction Summary
    19. =========================================================================================================================================================
    20. Install 7 Packages
    21. Total download size: 38 M
    22. Installed size: 195 M
    23. Is this ok [y/N]: y
    24. Downloading Packages:
    25. ...
    26. Installed:
    27. mariadb-connector-c-config-3.1.11-2.el8_3.noarch mecab-0.996-1.module_el8.4.0+2532+b8928c02.9.x86_64
    28. mysql-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64 mysql-common-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64
    29. mysql-errmsg-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64 mysql-server-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64
    30. protobuf-lite-3.5.0-13.el8.x86_64
    31. Complete!

    第四步:使能并且启动MySQL

    要用MySQL数据库服务器执行任何操作,我们需要首先启动这个服务。但首先,按以下使其能在系统启动时启动:

    1. [root@localhost dbuser]# systemctl enable mysqld
    2. Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

    接着启动MySQL守护程序:

    [root@localhost dbuser]# systemctl start mysqld
    

    我们通过执行以下能够验证MySQL正在运行:

    1. [root@localhost dbuser]# systemctl status mysqld
    2. ● mysqld.service - MySQL 8.0 database server
    3. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
    4. Active: active (running) since Tue 2022-06-28 16:41:22 CST; 6s ago
    5. Process: 34862 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
    6. Process: 34735 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
    7. Process: 34710 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    8. Main PID: 34817 (mysqld)
    9. Status: "Server is operational"
    10. Tasks: 38 (limit: 23504)
    11. Memory: 462.2M
    12. CGroup: /system.slice/mysqld.service
    13. └─34817 /usr/libexec/mysqld --basedir=/usr
    14. Jun 28 16:41:14 localhost.localdomain systemd[1]: Starting MySQL 8.0 database server...
    15. Jun 28 16:41:14 localhost.localdomain mysql-prepare-db-dir[34735]: Initializing MySQL database
    16. Jun 28 16:41:22 localhost.localdomain systemd[1]: Started MySQL 8.0 database server.

    第五步:在Rocky Linux中使MySQL安全

    最后一步是要使得刚安装的MySQL数据库服务器安全。原因是:默认,MySQL带有充满漏洞的默认设置出现,这些漏洞会被黑客利用。像这样,我们需要通过运行mysql_secure_installation脚本加固它。

    当执行这个脚本时,将提示你使用VALIDATE_PASSWORD插件,它确定了密码强度等级并且使得使用者只能设置健壮的密码。

    设置这个插件,输入'Y'并且按回车。这个插件提供了3种密码策略等级,即是:LOW, MEDIUM和STRONG。

    对应STRONG密码策略输入2并且按回车、

    接着,确定设置一个符合所选密码等级的强MYSQL根密码。

    1. [root@localhost dbuser]# mysql_secure_installation
    2. Securing the MySQL server deployment.
    3. Connecting to MySQL using a blank password.
    4. VALIDATE PASSWORD COMPONENT can be used to test passwords
    5. and improve security. It checks the strength of password
    6. and allows the users to set only those passwords which are
    7. secure enough. Would you like to setup VALIDATE PASSWORD component?
    8. Press y|Y for Yes, any other key for No: y
    9. There are three levels of password validation policy:
    10. LOW Length >= 8
    11. MEDIUM Length >= 8, numeric, mixed case, and special characters
    12. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
    13. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
    14. Please set the password for root here.
    15. New password:
    16. Re-enter new password:
    17. Estimated strength of the password: 100
    18. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
    19. By default, a MySQL installation has an anonymous user,
    20. allowing anyone to log into MySQL without having to have
    21. a user account created for them. This is intended only for
    22. testing, and to make the installation go a bit smoother.
    23. You should remove them before moving into a production
    24. environment.
    25. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    26. Success.
    27. Normally, root should only be allowed to connect from
    28. 'localhost'. This ensures that someone cannot guess at
    29. the root password from the network.
    30. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    31. Success.
    32. By default, MySQL comes with a database named 'test' that
    33. anyone can access. This is also intended only for testing,
    34. and should be removed before moving into a production
    35. environment.
    36. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
    37. ... skipping.
    38. Reloading the privilege tables will ensure that all changes
    39. made so far will take effect immediately.
    40. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    41. Success.
    42. All done!

     这个插件提供了一种密码强度的估计,在这种情况中,100。这表示我们满足了密码强度要求:一个强密码需要至少8个字符,其应该由数值,大小写和特殊字符组成。

    要继续设置密码,按'Y'。否则,按'n'回退并且做所需调整。

    对于接下来的提示,按'Y'移除匿名用户,防止root用户远程登陆,并且在进入到一个生产环境前,移除测试数据库。

    1. [root@localhost dbuser]# mysql -uroot -p
    2. Enter password:
    3. Welcome to the MySQL monitor. Commands end with ; or \g.
    4. Your MySQL connection id is 10
    5. Server version: 8.0.26 Source distribution
    6. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    11. mysql> SELECT_VERSION();
    12. 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 'SELECT_VERSION()' at line 1
    13. mysql> SELECT VERSION();
    14. +-----------+
    15. | VERSION() |
    16. +-----------+
    17. | 8.0.26 |
    18. +-----------+
    19. 1 row in set (0.00 sec)
    20. mysql>

    第六步:在Rocky Linux中连接到MySQL

    一旦做完,使用MySQL客户端按演示地连接数据库。证实提供的root密码。

    1. [dbuser@localhost ~]$ mysql -uroot -p
    2. Enter password:
    3. Welcome to the MySQL monitor. Commands end with ; or \g.
    4. Your MySQL connection id is 16
    5. Server version: 8.0.26 Source distribution
    6. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    11. mysql>

    你可以通过运行以下查询确认版本:

    1. mysql> SELECT VERSION();
    2. +-----------+
    3. | VERSION() |
    4. +-----------+
    5. | 8.0.26 |
    6. +-----------+
    7. 1 row in set (0.00 sec)
    8. mysql>

    在Rocky Linux或AlmaLinux上安装MySQL是一个非常简单和明白的过程。由于AppStrem仓库已经提供MySQL8.0模块stream, 没有必要添加任何第三方仓库。

  • 相关阅读:
    局域网内部服务器访问外部网络
    SpringCloud - 微服务
    海外接单被没收百万收入并处以罚款,承德的这位程序员到底做了什么?
    CSS学习笔记
    七、Request&Response
    数据治理实战——翼支付金融板块业务数仓建设和数据治理之路
    自然语音处理(NLP)系列(三)——什么是序列标注?
    docker小技能:容器IP和宿主机IP一致( Nacos服务注册ip为内网ip,导致Fegin无法根据服务名访问 )
    【网络安全---ICMP报文分析】Wireshark教程----Wireshark 分析ICMP报文数据试验
    DW大学生网页作业制作设计 ——旅游门户网站(21页)HTML+CSS+JavaScript
  • 原文地址:https://blog.csdn.net/yuyuyuliang00/article/details/125504815