开发者

How to connect database using one not in localhost

开发者 https://www.devze.com 2023-02-03 04:07 出处:网络
I want to develop application th开发者_如何转开发at my database is not in the localhost, like this

I want to develop application th开发者_如何转开发at my database is not in the localhost, like this

$db['default']['hostname'] = "192.168.0.120";

But the application said this A Database Error Occurred

Unable to connect to your database server using the provided settings.

can codeigniter using some server database instead of just localhost ?? or maybe something missing?


The server located at that IP address must be configured to allow remote MySQL connections, at least to port 3306 or whichever port MySQL has been configured to listen on.


In addition to BoltClock's answer above, it may also be necessary to grant the sql user proper permissions to connect remotely to the database.

Assuming that you are using MySQL, here are two (depending on how you would like it configured) different ways of performing that operation.

A) Allow remote connections for sql_user from IP 192.168.0.200:

mysql> GRANT ALL ON database.* TO 'sql_user'@'192.168.0.200' IDENTIFIED BY 'PASSWORD';

B) Allow remote connections for sql_user from any IP:

mysql> GRANT ALL ON database.* TO 'sql_user'@'%' IDENTIFIED BY 'PASSWORD';

Once done, you also need to flush/reload the privileges:

mysql> FLUSH PRIVILEGES;
0

精彩评论

暂无评论...
验证码 换一张
取 消