GNU/Linux >> Linux の 問題 >  >> Panels >> Panels

Ubuntu18.04にMySQLをインストールする方法

このチュートリアルでは、Ubuntu18.04にMySQLをインストールしてセキュリティを向上させる方法を紹介します。 MySQLは、最も人気があり、広く使用されているオープンソースのリレーショナルデータベース管理システムの1つです。これは、WordPress、Drupal、Joomla、MagentoなどのWebアプリケーションの構築に使用され、LAMP/LEMPオープンソースWebアプリケーションソフトウェアスタックの重要な部分です。このチュートリアルを書いている時点で、公式のUbuntuパッケージリポジトリからサポートされている最新バージョンはMySQL5.7です。始めましょう。

要件:

  • このチュートリアルでは、Ubuntuサーバーを使用します。
  • 完全なSSHルートアクセスまたはsudo権限を持つユーザー。

ステップ1:サーバーに接続する

始める前に、SSH経由でサーバーに接続する必要があります。 rootユーザーとしてサーバーに接続するには、次のコマンドを使用します。

ssh root@IP_ADDRESS -p PORT_NUMBER

必ずIP_ADDRESSとPORT_NUMBERを実際のサーバーのIPアドレスとSSHポート番号に置き換えてください。

ログインしたら、次のコマンドを実行して、サーバーが最新であることを確認します。

sudo apt update
sudo apt upgrade

ステップ2:MySQLをインストールする

次のコマンドは、公式のUbuntuリポジトリから最新のMySQL5.7サーバーをインストールします。

sudo apt install mysql-server

インストールが完了するとすぐに、MySQLWebサーバーが自動的に起動します。

インストールが成功したかどうか、およびMySQLがサーバーで実行されているかどうかを確認するには、次のコマンドを実行できます。

sudo systemctl status mysql

画面に次の出力が表示されます。

mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-02-08 02:05:27 CST; 2min 4s ago
 Main PID: 13853 (mysqld)
    Tasks: 27 (limit: 2321)
   CGroup: /system.slice/mysql.service
           └─13853 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

次のコマンドを使用して、サーバーの再起動時にMySQLサービスが自動的に起動するようにすることもできます。

sudo systemctl enable mysql

MySQLのバージョンは次のコマンドで確認することもできます:

mysql -V

出力:

mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper

ステップ3:MySQLを保護する

MySQLインストールのセキュリティを向上させ、MySQL rootユーザーのパスワードを設定するには、mysql_secure_installationを実行する必要があります。 MySQLパッケージに含まれているスクリプト。

スクリプトを実行するには、次のコマンドを実行します。

sudo mysql_secure_installation

出力:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

まず、パスワード検証プラグインの設定について尋ねられます。

VALIDATE PASSWORD PLUGIN 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 plugin?

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

このプラグインはパスワードの強度をチェックし、ユーザーが十分に安全なパスワードのみを設定できるようにします。
これを有効にするかどうかは完全にあなた次第ですが、強力なパスワードを使用することを常に強くお勧めします。
[はい]を選択すると、パスワード検証ポリシーのレベルを選択するように求められます:

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:

次に、rootユーザーのパスワードを設定するように求められます。次のステップに進むには、パスワードを入力して確認します。

Please set the password for root here.

New password:

Re-enter new password:

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

パスワードを設定すると、匿名ユーザーの削除、リモートrootログインの禁止、およびテストデータベースの削除についてさらにいくつかの質問が表示されます。それらすべてに「はい」と答える必要があります:

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!

ステップ4:MySQLにログインします

rootユーザーとしてMySQLWebサーバーにログインするには、次のコマンドを実行できます。

sudo mysql -u root -p

mysql_secure_installationで設定したMySQLルートパスワードを入力します スクリプト。

正常にログインすると、次の出力が表示されます。

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

ステップ5:MySQLデータベースサーバーの構成

データベースサーバーのパフォーマンスを最適化するために設定を変更するなど、追加の変更を行う場合は、/etc/mysql/my.cnfにあるMySQLのデフォルト構成ファイルを編集できます。 。

sudo nano /etc/mysql/my.cnf

変更を加えたら、データベースサーバーを再起動する必要があります。

sudo systemctl restart mysql

結論

以上–MySQL5.7がUbuntu18.04VPSに正常にインストールされました。以下を含むMySQL関連のチュートリアルについては、ブログを確認してください。

LinuxVPSパート1での基本的なMySQLデータベース管理

LinuxVPSパート2での基本的なMySQLデータベース管理

新しいMySQLユーザーを作成して権限を付与する方法

MySQLデータベースをバックアップおよび復元する方法

その他…

もちろん、Ubuntu Hostingをご利用の場合は、Ubuntu18.04VPSにMySQLをインストールする必要はありません。管理者に聞いてリラックスしてください。管理者はすぐにUbuntu18.04にMySQLをインストールします。

PS。 Ubuntu18.04VPSにMySQLをインストールする方法に関するこの投稿が気に入った場合 、下のボタンを使用してソーシャルネットワークで友達と共有するか、コメントセクションにコメントを残してください。ありがとう。


Panels
  1. Ubuntu14.04にDrupal7をインストールする方法

  2. Ubuntu14.04にJoomla3をインストールする方法

  3. Ubuntu16.04にMySQLをインストールする方法

  1. Ubuntu16.04にRをインストールする方法

  2. Ubuntu16.04にChamiloをインストールする方法

  3. Ubuntu18.04にLAMPをインストールする方法

  1. Ubuntu20.04にphpMyAdminをインストールする方法

  2. Ubuntu20.04にMySQLをインストールして使用する方法

  3. Ubuntu20.04にMySQLデータベースをインストールする方法