本文介绍在CentOS 8/RHEL 8 Linux服务器/工作站操作系统上安装MySQL 5.7数据库的方法。CentOS/RHEL 8 AppStream存储库仅包含MySQL 8.0软件包,并非所有的应用程序都支持MySQL 8,例如Jira需要MySQL 5.7及以下版本,本文就教大家在CentOS 8/RHEL 8系统上运行MySQL 5.7数据库。
步骤1:添加MySQL存储库 禁用MySQL默认的AppStream存储库: sudo dnf remove @mysql sudo dnf module reset mysql && sudo dnf module disable mysql EL 8没有MySQL存储库,因此我们将改用EL 7存储库,创建一个新的存储库文件: sudo vi /etc/yum.repos.d/mysql-community.repo 将以下数据粘贴到文件中: [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=0 [mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ enabled=1 gpgcheck=0 [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ enabled=1 gpgcheck=0
步骤2:在CentOS 8/RHEL 8上安装MySQL 5.7 添加存储库后,现在使用以下命令在CentOS 8/RHEL 8上安装MySQL 5.7: sudo dnf --enablerepo=mysql57-community install mysql-community-server 按y开始安装:
检查软件包的详细信息,以确认它是5.7: $ rpm -qi mysql-community-server Name: mysql-community-server Version: 5.7.28 Release: 1.el7 Architecture: x86_64 参考:为CentOS 8操作系统安装MySQL的方法,以安装MySQL 8为例。
步骤3:在CentOS 8/RHEL 8上配置MySQL 5.7 1、安装后,启动mysqld服务: sudo systemctl enable --now mysqld.service 2、复制为root用户生成的随机密码: grep 'A temporary password' /var/log/mysqld.log |tail -1 注意打印的密码: 2020-01-06T18:06:19.947403Z 1 [Note] A temporary password is generated for root@localhost: AS*5Rx%YY5+c 3、启动MySQL安全安装以更改root密码、禁止远程root登录、删除匿名用户并删除测试数据库: $ sudo mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: 使用生成的临时密码进行身份验证,这将要求为root用户设置新密码,如下: Change the password for root ? ((Press y|Y for Yes, any other key for No) : Yes New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?: Yes Remove anonymous users?: Yes Success. Disallow root login remotely? : Yes Success. Remove test database and access to it? : Yes - Dropping test database... Success. - Removing privileges on test database... Success. Reload privilege tables now? (Press y|Y for Yes) : Yes Success. All done! 可以使用在线密码生成器来获取复杂的密码。 4、以root用户身份连接到MySQL数据库并创建一个测试数据库: $ mysql -u root -p
5、创建测试数据库和用户: mysql> CREATE DATABASE test_db; Query OK, 1 row affected (0.09 sec) mysql> CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Strong34S;#"; Query OK, 0 rows affected (0.04 sec) mysql> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost'; Query OK, 0 rows affected (0.02 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.02 sec) 可以通过运行以下命令删除该测试数据库和用户: mysql> DROP DATABASE test_db; Query OK, 0 rows affected (0.14 sec) mysql> DROP USER 'test_user'@'localhost'; Query OK, 0 rows affected (0.11 sec) mysql> show databases;
步骤4:配置防火墙(仅适用于远程连接) 要允许远程连接,请在防火墙上允许3306端口: sudo firewall-cmd --add-service=mysql --permanent sudo firewall-cmd --reload 还可以限制来自受信任网络的访问: sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \ service name="mysql" source address="10.10.10.0/24" accept' 参考:在CentOS 8系统上配置和管理防火墙(Firewall)的方法。 至此,配置防火墙的操作完成。
相关主题 |