photoBy: http://binarywasteland.com/wp-content/uploads/201…
外部接続先を許可しよう
何でつながらなかったん?
どういうわけか、mysqlがつながらなくなってた。
原因は「外部サーバーから接続を許可していたのに、何かの影響で外部接続ができなくなってた・・・」ということ。
今回は外部からの接続方法を書きます。
まずは普通の書き方
public $default = array(
'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => '153.121.38.178', 'login' => 'he4452fraki', 'password' => 'hifaweki54532', 'database' => 'meigen', 'prefix' => 'meigen_', 'encoding' => 'utf8', );
これで 153.121.38.178 につながるはずだが・・・繋がらない。
localhostにしてみると?
public $default = array(
'host' => 'localhost', );
これならつながるんですね。
早速つながるようにする。
ちなみに今回のエラーは以下
Missing Database Connection
Error: A Database connection using "Mysql" was missing or unable to connect.
The database server returned this error: SQLSTATE[28000] [1045] Access denied for user 'hogeman'@'www8164uo.sakura.ne.jp' (using password: YES)
Notice: If you want to customize this error message, create app/View/Errors/missing_connection.ctp
ようは www8164uo.sakura.ne.jp から繋げないよってこと。
同じサーバーからでも localhost にしていないと外部接続になるので、外部から許可しろよってことらしい。
許可を与える
まずは root でログインし
mysql -u root -p
localhostで許可
grant all privileges on *.* to hoge@"localhost" identified by 'pass' with grant option ;
hoge ユーザーが、 localhost で pass というパスワードで接続できますよ。
このさい、 hoge の " も pass の ' も必須なので要注意。
では、エラーの元のサーバー www8164uo.sakura.ne.jp で許可を与える
grant all privileges on *.* to tarou@"www8164uo.sakura.ne.jp" identified by 'pass' with grant option ;
これで tarou さんが www8164uo.sakura.ne.jp サーバーから pass でログインできますよと。
% ですべてのサーバーとか書いてあったけど、それじゃログインできんかった。
ひとつずつ設定すべき。みたいよ。
参考
http://yosugi.hatenablog.jp/entry/2013/06/23/185240
http://ext.omo3.com/linux/mysql_host.html
http://tm.root-n.com/database:mysql:setup:allow_connect_remote_host
↧