1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[さくらVPS+Ubuntu]mysqlのインストール

1
Posted at

プロジェクトの本番環境構築時、公式見よう見まねでやったもののちょっと躓いたのでメモ。

環境

  • さくらVPSの1Gを契約している
  • OSはUbuntu(22.04)

手順

mysqlのインストール

初期状態ではmysqlがインストールされていないので、入れる。
その前にシステムアップデートをしておく。

sudo apt update -y
sudo apt upgrade -y

aptコマンドでmysql-serverをインストール

sudo apt install mysql-server -y

mysqlのセットアップ

セキュリティ設定ウィザードを起動

sudo mysql_secure_installation

sudoを忘れるとパスワードの入力を求められるので、必ずsudoをつける。初期生成されるユーザはパスワード無しで生成されるので、入力する値が存在せず、無駄に時間を食った。

VALIDATE PASSWORDプラグインを入れるか聞かれる。
yを入力するとユーザーのパスワードとして設定できる文字列に一定の制限をかけることができる。

私は不要なのでEnterキー押下。

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に接続できてしまうので削除する。
yを入力してEnter

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)  :

rootによるリモート接続を許可しないか聞かれる。
許可すると、どこからでもrootでmysqlに接続できちゃうのでめちゃくちゃダメ。
yを入力してEnter

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) :

testデータベースを削除するか聞かれる。
testデータベースはmysqlの親切で、勝手に作られる。
いらないのでyを入力してEnter

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を入力してEnter

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) :

あとはmysqlに接続して好きにやる。

参考

さくらは公式マニュアル豊富かつ読みやすくて最高なのだ。ありがとうございます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?