2
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 5 years have passed since last update.

外部サーバーからMySQLに接続する権限を付与する

Posted at

AppサーバとMySQLサーバが別サーバで動いている場合、アクセス権限が無いとMySQLに接続ができません。

接続が許可されているホストを確認


mysql> SELECT host FROM mysql.user;
+---------------+
| host          |
+---------------+
| 127.0.0.1     |
| localhost     |
+---------------+

ローカルからしか許可されてない

Appサーバーも許可ホストに追加する

GRANT ALL PRIVILEGES ON *.* TO {MySQLのユーザ名}@'AppサーバーのIP' IDENTIFIED BY '{MySQLのパスワード}' WITH GRANT OPTION;

※ 今回は全権与えてるので、自分の環境に応じて変更が必要

確認

mysql> SELECT host FROM mysql.user;
+---------------+
| host          |
+---------------+
| 127.0.0.1     |
| localhost     |
| AppサーバーのIP |
+---------------+
2
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
2
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?