16
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PR: デジタル創作サークルUniProject
UniProject公式HP

「どうしてもMySQLを外部公開しなければならない」
そんな状況向けに 最低限やるべき設定 をまとめます。


大前提

可能なら 外部公開しない。
それが一番安全です。


1. bind-address を限定する

bind-address = 0.0.0.0

これは危険です。

bind-address = 192.168.1.10

必要なIPだけに限定 します。


2. ユーザーの接続元を限定

CREATE USER 'appuser'@'%' IDENTIFIED BY 'password';

これはNG。

CREATE USER 'appuser'@'1.2.3.4' IDENTIFIED BY 'password';

3. 権限は最小限

GRANT ALL PRIVILEGES ON *.* TO 'appuser';

最悪です。

GRANT SELECT, INSERT, UPDATE ON appdb.* TO 'appuser';

4. root の外部接続禁止

SELECT host FROM mysql.user WHERE user='root';

外部接続可能なら即修正。


5. ファイアウォールで制限

  • 3306は特定IPのみ
  • 国ごとブロックも検討

6. 定期バックアップ

mysqldump appdb > backup.sql
  • cronで自動化
  • 別サーバーへ転送

まとめ

  • 外部公開は最後の手段
  • IP制限と権限分離は必須
  • バックアップは必ず取る
16
0
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
16
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?