GNU/Linux >> Linux の 問題 >  >> Fedora

MysqlServer8をFedora34/35にインストールして構成する方法

Mysqlは通常、一般的なLAMPまたはLEMP(Linux、Apache / Nginx、MySQL / MariaDB、PHP / Python / Perl)スタックの一部としてインストールされます。リレーショナルモデルと構造化照会言語(SQL)を実装して、データを管理および照会します。

このガイドでは、mysql8をFedora34/35にインストールします

関連コンテンツ

  • Fedora35にMariadbをインストールして設定する方法
  • Mysql8をRockyLinux/Centos8にインストールする方法
  • Ubuntu20.04にmysql8をインストールしてセットアップする方法
  • DockerとDockerでMysql8を実行する方法-作成
  • Ansibleを使用してCentos8にMysql8をインストールして初期化する
  • MySQLのアクセス許可–データベースユーザーの作成、更新、削除
  • Centos 8にNginx、WordPress、Mysql8をインストールしてセットアップする
  • Mariadbの例を使用してテラフォームでRDSインスタンスを作成する

目次

  1. サーバーが最新であることを確認する
  2. Mysql8サーバーのインストール
  3. mysqlサービスの開始と有効化
  4. mysqlインストールの保護
  5. mysqlインストールのテスト

サーバーが最新であることを確認する

先に進む前に、Fedoraサーバーが最新であることを確認しましょう。次のコマンドを使用して、サーバーパッケージを更新します。

sudo dnf -y update

Mysql8サーバーのインストール

パッケージが更新されたので、mysqlサーバーのインストールに進むことができます。このコマンドを使用して、mysqlサーバーを提供するサーバー上のパッケージを検索します。

$ sudo dnf search mysql-server
Last metadata expiration check: 2:06:28 ago on Sun 31 Oct 2021 06:18:24 AM UTC.
========================================================================================= Name Matched: mysql-server ==========================================================================================
community-mysql-server.x86_64 : The MySQL server and related files

このコマンドを使用して、リストされたパッケージの情報をチェックし、必要なmysqlバージョンが提供されていることを確認します。

$ sudo dnf info community-mysql-server
Last metadata expiration check: 2:12:13 ago on Sun 31 Oct 2021 06:18:24 AM UTC.
Installed Packages
Name         : community-mysql-server
Version      : 8.0.26
Release      : 1.fc34
Architecture : x86_64
Size         : 106 M
Source       : community-mysql-8.0.26-1.fc34.src.rpm
Repository   : @System
From repo    : updates
Summary      : The MySQL server and related files
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. This package contains
             : the MySQL server and some accompanying files and directories.

次のコマンドを使用してインストールします:

sudo dnf install -y community-mysql-server

インストールしたら、次のコマンドを使用してインストールを確認します。

$ rpm -qi community-mysql-server
Name        : community-mysql-server
Version     : 8.0.26
Release     : 1.fc34
Architecture: x86_64
Install Date: Sun 31 Oct 2021 08:28:55 AM UTC
Group       : Unspecified
Size        : 111652520
License     : GPLv2 with exceptions and LGPLv2 and BSD
Signature   : RSA/SHA256, Tue 17 Aug 2021 04:01:38 PM UTC, Key ID 1161ae6945719a39
Source RPM  : community-mysql-8.0.26-1.fc34.src.rpm
Build Date  : Wed 11 Aug 2021 09:34:44 PM UTC
Build Host  : buildvm-x86-18.iad2.fedoraproject.org
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : http://www.mysql.com
Bug URL     : https://bugz.fedoraproject.org/community-mysql
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.

mysqlサービスの開始と有効化

この時点まで、システムにmysqlサービスをインストールすることができました。デフォルトではサービスは開始されないため、次のコマンドを発行して開始する必要があります。

sudo systemctl start mysqld

再起動時にサービスを開始できるようにするには、次のコマンドを使用します。

$ sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

次に、サービスのステータスをチェックして、実際に実行されていることを確認します。

$ sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: active (running) since Sun 2021-10-31 08:37:07 UTC; 1min 21s ago
   Main PID: 55677 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 4603)
     Memory: 449.0M
        CPU: 3.328s
     CGroup: /system.slice/mysqld.service
             └─55677 /usr/libexec/mysqld --basedir=/usr

Oct 31 08:36:58 new-cloud systemd[1]: Starting MySQL 8.0 database server...
Oct 31 08:36:58 new-cloud mysql-prepare-db-dir[55597]: Initializing MySQL database
Oct 31 08:37:07 new-cloud systemd[1]: Started MySQL 8.0 database server.

Active: active (running) since ... サービスが稼働中であることを示します。

journalctlコマンドを使用してMySQL8サービスログを次のように表示するには:

$ sudo journalctl -u mysqld -xe
$ sudo tail -f /var/log/mysql/mysqld.log

mysqlインストールの保護

MySQLには、MySQLのセキュリティを向上させるためにいくつかのデフォルト設定オプションを変更できるセキュリティスクリプトが含まれています。

セキュリティスクリプトを使用するには、次のコマンドを実行します。

sudo mysql_secure_installation

これにより、MySQLインストールのセキュリティオプションに特定の変更を加えるかどうかを尋ねる一連のプロンプトが表示されます。これらのオプションは次のとおりです。

  • rootユーザーのパスワードの設定
  • 強力なパスワードが使用されることを保証するVALIDATEPASSWORDCOMPONENTを有効にする
  • 匿名ユーザーの削除
  • rootを無効にしてリモートログインする
  • テストデータベースの削除

これが私のサーバーからの出力例です:

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

MySQLインストールのテスト

次のコマンドでmysqlのバージョンを確認しましょう:

$ mysql -V
mysql  Ver 8.0.26 for Linux on x86_64 (Source distribution)

これで、rootとしてログインできます 上記で指定したユーザーとパスワード。

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, 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>
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.26    |
+-----------+
1 row in set (0.00 sec)

結論

この記事では、Fedora34/35にmysql8のインストールとテストを行うことができました


Fedora
  1. Fedora35/34にSkypeをインストールする方法

  2. Fedora35/34にGradleをインストールする方法

  3. Fedora34/35にPodmanをインストールして使用する方法

  1. Fedora34にRedis6をインストールして設定する方法

  2. Fedora34にPostgres14をインストールして設定する方法

  3. Fedora35にAnsibleをインストールして設定する方法

  1. Fedora35/34にApacheMavenをインストールする方法

  2. Mongodb5をFedora34/35にインストールする方法

  3. Fedora35にMariadbをインストールして設定する方法