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

![]( /img/34bf4ac67218ed27bd57e858f9d4f604/scjz0ev1tk.jpeg)Xuemeng Technology

この記事は最初に公開されました:

https://www.itcoder.tech/posts/how-to-install-mysql-on-ubuntu-20-04/

[ MySQL](https://www.mysql.com/)は、最も人気のあるオープンソースのリレーショナルデータベース管理システムです。高速で使いやすく、拡張も簡単で、人気のある「LAMP」と「LEMP」の一部です。

このガイドでは、Ubuntu 20.04に[MySQL](https://cloud.tencent.com/product/cdb?from=10680)をインストールして保護する方法について説明します。

1.前提条件##

sudoユーザーとしてログインしていることを確認してください

2.MySQLをUbuntuにインストールします##

この記事を書いている時点で、Ubuntuソースリポジトリの最新のMySQLバージョン番号はMySQL8.0です。これをインストールするには、次のコマンドを実行します。

sudo apt update
sudo apt install mysql-server

インストールが完了すると、MySQLサービスが自動的に開始されます。 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 Tue 2020-04-2820:59:52 UTC; 10min ago
 Main PID:8617(mysqld)
  Status:"Server is operational"...

3、MySQLの保護と強化##

MySQLインストールファイルには、「mysql_secure_installation」というスクリプトが付属しており、データベースサーバーのセキュリティを簡単に向上させることができます。

パラメータなしでこのスクリプトを実行します。

sudo mysql_secure_installation

MySQLユーザーパスワードの強度をテストし、セキュリティを向上させるために使用される VALIDATE PASSWORDPLUGINを構成するように求められます。

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

パスワード検証戦略には、低レベル、中レベル、高レベルの3つのレベルがあります。確認パスワードプラグインを設定する場合は、「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

次回プロンプトが表示されたら、MySQLルートユーザーのパスワードを設定するように求められます。

Please set the password for root here.

New password: 

Re-enter newpassword:

パスワード検証プラグインを設定している場合、このスクリプトは新しいパスワードの強度を表示します。 yを入力して、パスワードを確認します。

Estimated strength of the password:50 
Do you wish to continuewith the password provided?(Press y|Y for Yes, any other key for No): y

次に、匿名ユーザーを削除し、ローカルマシンへのルートユーザーアクセスを制限し、テストデータベースを削除して、権限テーブルを再読み込みするように求められます。すべての質問に「y」と答える必要があります。

第四に、rootユーザーとしてログインします##

MySQlクライアントツールを使用して、コマンドラインでMySQLサーバーと対話します。このMySQLクライアントは、MySQLサーバーインストールパッケージの依存パッケージとしてインストールされています。

MySQL 8.0では、rootユーザーはデフォルトで auth_socketプラグインによって許可されています。

auth_socketプラグインは、Unixソケットファイルを介して localhostに接続しているすべてのユーザーを認証します。これは、パスワードを指定してrootとして認証できないことを意味します。

rootユーザーとしてMySQLサーバーにログインし、次のように入力します。

sudo mysql

次のようにMySQLシェルが表示されます。

Welcome to the MySQL monitor.  Commands end with; or \g.
Your MySQL connection id is 12
Server version:8.0.19-0ubuntu5(Ubuntu)Copyright(c)2000,2020, 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>

rootとしてMySQLサーバーにログインし、phpMyAdminなどの他のプログラムを使用する場合は、2つのオプションがあります。

1つ目は、認証方法を auth_socketから mysql_native_passwordに変更することです。次のコマンドを実行することでそれを行うことができます:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
FLUSH PRIVILEGES;

2番目のオプションである推奨オプションは、すべてのデータベースへのアクセス権を持つ新しい独立した管理ユーザーを作成することです。

GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';

5、要約##

Ubuntu20.04にMySQLをインストールする方法を説明しました。データベースがオンラインで実行されているので、次のステップは[MySQLユーザーとデータベースの管理方法](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/)を学ぶことです。


ご不明な点がございましたら、以下の方法でお問い合わせください。

WeChat:sn0wdr1am86

WeChatグループ:上記のWeChatを追加し、WeChatグループにコメントします

QQ: 3217680847

QQグループ:82695646

Recommended Posts

Ubuntu20.04にMySQLをインストールする方法
Ubuntu14.04にMySQLをインストールする方法
Ubuntu 18.04(linux)にMySQLをインストールする方法
Ubuntu18.04に最新のMySQLをインストールする方法
Ubuntu20.04にRubyをインストールする方法
Ubuntu20.04にJavaをインストールする方法
Ubuntu20.04にVirtualBoxをインストールする方法
Ubuntu20.04にElasticsearchをインストールする方法
UbuntuにProtobuf3をインストールするための詳細なチュートリアル
Ubuntu20.04にNginxをインストールする方法
Ubuntu20.04にApacheをインストールする方法
Ubuntu20.04にGitをインストールする方法
Ubuntu16.04にNode.jsをインストールする方法
Ubuntu20.04にVagrantをインストールする方法
Ubuntu14.04にBacula-Webをインストールする方法
Ubuntu16.04にPostgreSQLをインストールする方法
Ubuntu20.04にGitをインストールする方法
Ubuntu18.04にAnaconda3をインストールする方法
Ubuntu14.04にmysqlをインストールする方法
Ubuntu18.04にMemcachedをインストールする方法
Ubuntu16.04にJenkinsをインストールする方法
Ubuntu14.04にMemSQLをインストールする方法
Ubuntu20.04にGoをインストールする方法
Ubuntu16.04にMongoDBをインストールする方法
Ubuntu14.04にMailpileをインストールする方法
Ubuntu16.04にPrestaShopをインストールする方法
Ubuntu20.04にSkypeをインストールする方法
Ubuntu20.04にJenkinsをインストールする方法
Ubuntu18.04にPython3.8をインストールする方法
Ubuntu18.04にKVMをインストールする方法
Ubuntu20.04にKVMをインストールする方法
ubuntu14.04にopencv3.0.0をインストールする方法
Ubuntu20.04にAnacondaをインストールする方法
Ubuntu16.04にPrometheusをインストールする方法
Ubuntu18.04にJenkinsをインストールする方法
Ubuntu20.04にApacheをインストールする方法
Ubuntu20.04にRをインストールする方法
Ubuntu16.04にMoodleをインストールする方法
Ubuntu14.04にSolr5.2.1をインストールする方法
Ubuntu16.04にTeamviewerをインストールする方法
Ubuntu20.04にMariaDBをインストールする方法
Ubuntu20.04にNginxをインストールする方法
Ubuntu20.04にMonoをインストールする方法
Ubuntu20.04にGoをインストールする方法
Ubuntu20.04にZoomをインストールする方法
Ubuntu14.04にmysqlをインストールする方法
Ubuntu16.04にNginxをインストールする方法
Ubuntu20.04にOpenCVをインストールする方法
Ubuntu20.04にSpotifyをインストールする方法
Ubuntu18.04にPostmanをインストールする方法
Ubuntu16.04にGo1.6をインストールする方法
Ubuntu18.04にGoをインストールする方法
Ubuntu20.04にPostgreSQLをインストールする方法
Ubuntu18.04にVLCをインストールする方法
Ubuntu20.04にTeamViewerをインストールする方法
Ubuntu20.04にWebminをインストールする方法
Ubuntu18.04にMySQLWorkbenchをインストールして使用する方法
Ubuntu14.04にmysqlをインストールします
Ubuntu18.04にDockerComposeをインストールする方法
RaspberryPiにUbuntuをインストールする方法
Ubuntu14.04にBaculaServerをインストールする方法