如何在Fedora 32/31/30/29上安装MySQL 8.0

时间:2020-02-23 14:40:57  来源:igfitidea点击:

在本教程中,我们将介绍如何在Fedora 32/31/Fedora 30/Fedora 29 Server或者Workstation上安装MySQL 8.0。如果我们使用的是旧版本的MySQL Server(例如5.7),则可能需要就地升级或者转储所有数据,升级软件包并将所有数据库数据重新导入到已安装的新MySQL 8.0中。

添加MySQL 8.0社区存储库

要在Fedora 31/30/29上安装MySQL 8.0,我们需要添加MySQL 8.0社区存储库:

将MySQL 8.0存储库添加到Fedora 32/31

--- Fedora 32 --
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc32-1.noarch.rpm

--- Fedora 31 --
sudo dnf -y install https://repo.mysql.com//mysql80-community-release-fc31-1.noarch.rpm

将MySQL 8.0存储库添加到Fedora 30

运行命令。

sudo dnf -y install https://repo.mysql.com//mysql80-community-release-fc30-1.noarch.rpm

将MySQL 8.0存储库添加到Fedora 29

在Fedora 29终端上运行以下命令:

sudo dnf -y install https://repo.mysql.com//mysql80-community-release-fc29-2.noarch.rpm

这会将存储库文件写入/etc/yum.repos.d/mysql-community.repo

在Fedora 32/31/30/29上安装MySQL Server 8.0

添加存储库并确认启用后,请运行以下命令将MySQL 8.0安装到Fedora 32/31/30/29:

sudo dnf -y install mysql-community-server

安装后,可以从以下位置查看软件包信息:

$dnf info mysql-community-server
Last metadata expiration check: 0:40:41 ago on Sun 04 Nov 2016 09:55:41 AM UTC.
Installed Packages
Name         : mysql-community-server
Version      : 8.0.13
Release      : 1.fc29
Arch         : x86_64
Size         : 1.8 G
Source       : mysql-community-8.0.13-1.fc29.src.rpm
Repo         : @System
From repo    : mysql80-community
Summary      : A very fast and reliable SQL database server
URL          : http://www.mysql.com/
License      : Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Description  : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
             : and robust SQL (Structured Query Language) database server. MySQL Server
             : is intended for mission-critical, heavy-load production systems as well
             : as for embedding into mass-deployed software. MySQL is a trademark of
             : Oracle and/or its affiliates
             : 
             : The MySQL software has Dual Licensing, which means you can use the MySQL
             : software free of charge under the GNU General Public License
             : (http://www.gnu.org/licenses/). You can also purchase commercial MySQL
             : licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
             : the GPL. See the chapter "Licensing and Support" in the manual for
             : further info.
             : 
             : The MySQL web site (http://www.mysql.com/) provides the latest news and
             : information about the MySQL software.  Also please see the documentation
             : and the manual for more information.
             : 
             : This package includes the MySQL server binary as well as related utilities
             : to run and administer a MySQL server.

在Fedora 32/31/30/29上配置MySQL服务器

在Fedora 32/31/30/29上安装MySQL 8.0后,我们需要进行初始配置以保护它。

1.启动并启用mysqld服务:

sudo systemctl start mysqld.service
sudo systemctl enable mysqld.service

2.复制为root用户生成的随机密码

grep 'A temporary password' /var/log/mysqld.log |tail -1

注意打印的密码:

A temporary password is generated for theitroad@localhost: 1ph/axo>vJe;

3.启动MySQL安全安装以更改root密码,禁止远程root登录,删除匿名用户并删除测试数据库。

$mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:

使用我们生成的临时密码进行身份验证。然后像下面这样配置MySQL 8.0安装:

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
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2016, 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() |
+-----------+
| 8.0.13    |
+-----------+
1 row in set (0.00 sec)

创建一个测试数据库和用户

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.1.1.0/24" accept'