如何在Fedora 32/31/30/29上安装MySQL 5.7
问题:如何在Fedora 32/31/30/29上安装MySQL 5.7? MySQL是基于结构化查询语言(SQL)的最健壮的生产级RDBMS。它的开发得到了Oracle Corporation的支持。凭借其可靠的可靠性,性能和易用性,MySQL已成为基于Web的应用程序的首选数据库选择。
一些使用MySQL的大包括Facebook,Twitter,YouTube等。 MySQL背后有一个庞大的用户社区,因此我们始终可以在需要时获得帮助。
在Fedora 32/31/30/29上安装MySQL 5.7
MySQL 5.7的软件包在Fedora的Oracle上游存储库中可用。使用特定于每个发行版的以下命令添加存储库。
将MySQL 8.0存储库添加到Fedora 32
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc32-1.noarch.rpm
将MySQL 8.0存储库添加到Fedora 31
sudo dnf -y install https://repo.mysql.com//mysql80-community-release-fc31-1.noarch.rpm
对于Fedora 30:
sudo dnf -y install https://repo.mysql.com//mysql80-community-release-fc30-1.noarch.rpm
对于Fedora 29:
sudo dnf -y install https://repo.mysql.com//mysql80-community-release-fc29-2.noarch.rpm
上面的命令会将存储库内容添加到文件/etc/yum.repos.d/mysql-community.repo中。
安装的默认软件包mysql-community-server是用于MySQL 8的。要在Fedora 32/31/30/29上安装MySQL 5.7.
禁用MySQL 8存储库:
sudo dnf config-manager --disable mysql80-community
然后为MySQL 5.7启用通道。
sudo dnf config-manager --enable mysql57-community
然后在Fedora上安装MySQL 5.7:
sudo dnf install mysql-community-server
按y键开始安装。
........................................... Transaction Summary Install 49 Packages Total download size: 214 M Installed size: 970 M Is this ok [y/N]: y
也同意添加GPG密钥。
Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <theitroad@localhost>" Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Is this ok [y/N]: y
如果失败,请手动添加MySQL 5.7的存储库:
sudo tee /etc/yum.repos.d/mysql-community-5.7.repo<<EOF # 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/x86_64/ enabled=1 gpgcheck=0 EOF
然后在Fedora 32/31/30/29上安装MySQL 5.7:
sudo dnf config-manager --disable mysql80-community sudo dnf config-manager --enable mysql57-community sudo dnf install mysql-community-server
按Y键开始安装:
Transaction Summary ================================================================================================================================================================== Install 48 Packages Total download size: 213 M Installed size: 914 M Is this ok [y/N]: y
要查看已安装软件包的特定详细信息,请使用:
$rpm -qi mysql-community-server Name : mysql-community-server Version : 5.7.31 Release : 1.el7 Architecture: x86_64 Install Date: Mon 21 Sep 2017 10:33:07 AM UTC Group : Applications/Databases Size : 798880218 License : Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field. Signature : DSA/SHA1, Wed 03 Jun 2017 10:08:07 AM UTC, Key ID 8c718d3b5072e1f5 Source RPM : mysql-community-5.7.31-1.el7.src.rpm Build Date : Tue 02 Jun 2017 11:48:16 AM UTC Build Host : siv27.no.oracle.com Packager : MySQL Release Engineering <theitroad@localhost> Vendor : Oracle and/or its affiliates URL : http://www.mysql.com/ Summary : A very fast and reliable SQL database server
在Fedora 32/31/30/29上配置MySQL 5.7.
2.1安装后,启动mysqld服务。
sudo systemctl enable --now mysqld.service
2.2复制生成的root用户随机密码:
sudo grep 'A temporary password' /var/log/mysqld.log |tail -1
记下打印的密码:
2019-05-08T16:59:02.412078Z 1 [Note] A temporary password is generated for theitroad@localhost: -gv9kyqud*,U
2.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!
我们可以使用在线密码生成器来获取复杂的密码。
2.4以root用户身份连接到MySQL数据库并创建测试数据库。
$mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.31 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names Jan be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.31 | +-----------+ 1 row in set (0.00 sec) mysql> \q Bye
2.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; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql> QUIT Bye
配置防火墙
要允许远程连接,请在防火墙上允许端口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'