アンドロイド

Debian 9にmysqlをインストールする方法

FTL Advanced Edition Gameplay On Linux

FTL Advanced Edition Gameplay On Linux

目次:

Anonim

Debian 9 Stretch MySQLのリリースにより、世界で最も人気のあるオープンソースリレーショナルデータベース管理システムがDebianのリポジトリで使用できなくなり、MariaDBがデフォルトのデータベースシステムになりました。 MariaDBは、MySQLの下位互換性のあるバイナリドロップインの代替品です。

このチュートリアルでは、MySQL AptリポジトリからDebian 9マシンにMySQLをインストールして保護する方法を示します。 アプリケーションに特定の要件がない場合は、Debian 9のデフォルトのデータベースシステムであるMariaDBを使用する必要があります。

前提条件

このチュートリアルを続ける前に、sudo特権を持つユーザーとしてログインしていることを確認してください。

ステップ1:MySQLリポジトリの構成

MySQL APTリポジトリをシステムに追加するには、リポジトリダウンロードページに移動し、次のwgetコマンドを使用して最新リリースパッケージをダウンロードします。

wget

ダウンロードが完了したら、次のコマンドでリリースパッケージをインストールします。

sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

インストールするMySQLバージョンを選択できる構成メニューが表示されます。

ステップ3:MySQLインストールの検証

インストールが完了すると、MySQLサービスが自動的に開始されます。

次のように入力して、MySQLサービスのステータスを確認できます。

sudo systemctl status mysql

● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: Active: active (running) since Thu 2018-08-02 17:22:18 UTC; 18s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 14797 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (co Main PID: 14832 (mysqld) Status: "SERVER_OPERATING" Tasks: 37 (limit: 4915) CGroup: /system.slice/mysql.service └─14832 /usr/sbin/mysqld

ステップ4:MySQLの保護

mysql_secure_installation コマンドを実行して、rootパスワードを設定し、MySQLインストールのセキュリティを改善します。

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:

MySQLユーザーのパスワードの強度をテストするために使用される VALIDATE PASSWORD PLUGIN を設定するよう求められます。 パスワード検証ポリシーには、低、中、強力の3つのレベルがあります。 パスワード検証プラグインを設定しない場合は、 ENTER 押し ENTER

Please set the password for root here. New password: Re-enter new password:

次のプロンプトで、MySQL 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!

rootパスワードを設定すると、スクリプトは匿名ユーザーの削除、rootユーザーによるローカルマシンへのアクセスの制限、テストデータベースの削除を要求します。 すべての質問に「Y」(はい)と答える必要があります。

ステップ5:コマンドラインからMySQLに接続する

ターミナルを介してMySQLと対話するには、MySQLサーバーパッケージの依存関係としてインストールされるMySQLクライアントを使用します。

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

mysql -u root -p

mysql_secure_installation スクリプトの実行時に以前に設定したルートパスワードの入力を mysql_secure_installation られます。

パスワードを入力すると、次のようにMySQLシェルが表示されます。

Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 10 Server version: 8.0.12 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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>

データベースを作成する

MySQLシェルに接続したら、次のコマンドを入力して新しいデータベースを作成できます。

CREATE DATABASE new_database;

Query OK, 1 row affected (0.00 sec)

テーブルを作成する

データベースを作成したので、データを保存するテーブルを作成できます。

テーブルを作成するためのSQLステートメントを実行する前に、データベースに接続する必要があります。

use new_database;

この例では、 id name email name 3つのフィールドを持つ contacts という名前の簡単なテーブルを作成し email

CREATE TABLE contacts (id INT PRIMARY KEY, name VARCHAR(30), email VARCHAR(30));

Query OK, 1 row affected (0.00 sec)

結論

このチュートリアルでは、MySQLサーバーをDebian 9サーバーにインストールして保護する方法を示しました。 また、MySQLシェルに接続する方法と、新しいデータベースとテーブルを作成する方法も示しました。

MySQLサーバーが稼働し、コマンドラインからMySQLサーバーに接続する方法がわかったので、次のガイドを確認してください。

mysql debian