もっと詳しく

このガイドは、Ubuntu22.04にMySQL8をインストールする方法に関する段階的なチュートリアルを提供します。 MySQL は、高速で安定した真のマルチユーザー、マルチスレッドSQLデータベースサーバーであり、その主な目標は、速度、堅牢性、および使いやすさです。 MySQL 8が提供する機能の包括的な説明を表示するには、次のURLに移動してください。 MySQL8リファレンスマニュアル

MySQL8をUbuntu22.04にインストールします

Ubuntu 22.04には、デフォルトのリポジトリにMySQL8が付属しています。 これにより、Ubuntu22.04へのMySQL8のインストールがシームレスなタスクになります。

続行する前に、システムパッケージを更新およびアップグレードしてください。

apt update

次に、以下のコマンドを実行して、MySQL8をUbuntu22.04にインストールします。

apt install mysql-server

このコマンドは、MySQL8と必要なすべてのパッケージ依存関係をインストールします。

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl
  liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
  libdata-dump-perl libipc-sharedcache-perl libbusiness-isbn-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl
  liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 28 newly installed, 0 to remove and 3 not upgraded.
Need to get 29.0 MB of archives.
After this operation, 240 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Ubuntu22.04へのMySQL8の安全なインストール

MySQLには、と呼ばれるセキュリティスクリプトが付属しています mysql_secure_installation これにより、次の方法でMySQLインストールの初期セキュリティを実装できます。

  • ルートアカウントのパスワードを設定できます。
  • ローカルホストの外部からアクセス可能なルートアカウントを削除できます。
  • 匿名ユーザーアカウントを削除できます。
  • テストデータベース(デフォルトでは、匿名ユーザーも含めてすべてのユーザーがアクセスできます)と、test_で始まる名前のデータベースに誰でもアクセスできるようにする特権を削除できます。

スクリプトは、実行するだけで簡単に実行できます。

mysql_secure_installation

スクリプトを実行すると、パスワードの複雑さのチェックを実装するかどうかを確認するメッセージが表示されます。 パスワードの強度の選択を受け入れます。

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
...

次に、rootパスワードを設定し、他のプロンプトを受け入れて、匿名データベースユーザーを削除し、リモートrootログインを禁止し、テストデータベースを削除し、特権テーブルを再ロードして、MySQLに変更を加えます。

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.28-0ubuntu4 for Linux on x86_64 ((Ubuntu))

MySQL8にログインする

これで、上記で設定したパスワードを使用して、rootユーザーとしてMySQL8に接続できます。

ただし、MySQL8はデフォルトでunixソケット認証プラグインを使用することに注意してください。 これにより、ローカルホストからrootユーザーまたはパスワードなしでsudo権限を持つユーザーとしてMySQLサーバーにログインできます。

したがって、以下のコマンドのいずれかを実行すると、MySQLサーバーにログインします。

mysql
mysql -u root

以下のコマンドを実行し、プロンプトが表示されたらEnterキーを押して空のパスワードを入力しても、ログインする必要があります。

mysql -u root -p

MySQLにログインしたら、コマンドを実行してバージョンを確認することもできます。

mysql> SHOW VARIABLES LIKE "%version%";
+--------------------------+-----------------+
| Variable_name            | Value           |
+--------------------------+-----------------+
| admin_tls_version        | TLSv1.2,TLSv1.3 |
| immediate_server_version | 999999          |
| innodb_version           | 8.0.28          |
| original_server_version  | 999999          |
| protocol_version         | 10              |
| replica_type_conversions |                 |
| slave_type_conversions   |                 |
| tls_version              | TLSv1.2,TLSv1.3 |
| version                  | 8.0.28-0ubuntu4 |
| version_comment          | (Ubuntu)        |
| version_compile_machine  | x86_64          |
| version_compile_os       | Linux           |
| version_compile_zlib     | 1.2.11          |
+--------------------------+-----------------+
13 rows in set (0.02 sec)

パスワードを有効にする-MySQL8認証に基づく

上記のように、MySQL8はデフォルトでunixソケット認証プラグインを使用します。

SELECT plugin from mysql.user where User='root';
+-------------+
| plugin      |
+-------------+
| auth_socket |
+-------------+
1 row in set (0.00 sec)

パスワードベースの認証を有効にするには、MySQLネイティブパスワードプラグインに切り替える必要があります。 mysql_native_password

UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'auth_socket';

それが完了したら、rootユーザーのパスワードをリセットします。

ALTER USER [email protected] identified by 'myS[email protected]';

特権テーブルをリロードします。

flush privileges;

変更を確認します。

SELECT User,plugin from mysql.user where User='root';
+------+-----------------------+
| User | plugin                |
+------+-----------------------+
| root | mysql_native_password |
+------+-----------------------+
1 row in set (0.00 sec)

データベース接続を終了し、rootとして再度ログインしてみてください。

mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

どうぞ。 ローカルホストでMySQLrootユーザーのパスワード認証を無効にしました。

これで、Ubuntu22.04にMySQL8をインストールする方法に関するガイドは終わりです。

関連チュートリアル

CentOS8にMySQL8をインストールします

MySQL8をDebian10Busterにインストールします

MySQL8をFreeBSD12にインストールします

MySQL8をDebian9にインストールします

The post MySQL8をUbuntu22.04にインストールします appeared first on Gamingsym Japan.