| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Jul 2004 Location: just go to left side from my right neighbour...
Posts: 32
![]() | Website A using database of Website B ? I had 2 webs in different hosting places. How to connecting php script in website A to using database in website B? |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: May 2004 Location: NYC
Posts: 236
![]() ![]() ![]() | It's kinda tedious and it varies based on the database system involved (Postgres is different from mysql is different from Oracle, etc.) but here's the rough process for mysql:????: NamePros.com http://www.namepros.com/programming/308004-website-a-using-database-website-b.html 1. The database on website B must be configured to allow external connections. With mysql, for example, you need to COMMENT OUT this line in my.cnf: #skip-networking And you then need to set external access permissions in the database using the GRANT command. This can be complicated, based on who you're logging in as, what IPs you want to allow, etc. Here's an example line, that allows user "root" to access the system from any IP: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' 2. Make sure that the port on which the database listens (3306 by default for mysql) is open on any firewall on both websites B and A. 4. You can now connect as normal, but instead of using "localhost" as your host string, you'd use "somesite.com" or even just the IP address if you want. Note that if you want to use a specific hostname ONLY for the database (like db.somesite.com) you'll need to set up a DNS entry for it on website B. |
| |
| | #4 (permalink) | ||||
| Forum Moderator ![]() Join Date: Aug 2006 Location: USA
Posts: 2,152
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| ||||
| |
| | #5 (permalink) |
| NamePros Regular Join Date: May 2004 Location: NYC
Posts: 236
![]() ![]() ![]() | enlytend, agreed. If you can restrict access at the grant level to specific IPs/hosts/CIDR blocks, all the better. Sometimes I have to access dbs using remote tools from unknown locations, so for those circumstances I use very loose GRANT permissions. However, to mitigate this, we then monitor logins via a BFD-like system so that we can dynamically block hack attempts at the firewall, and we also don't allow root logins with full privileges. ????: NamePros.com http://www.namepros.com/showthread.php?t=308004 So I guess that was a pretty bad sample line after all Thanks for pointing this out.(But I did say this stuff was tricky ) |
| |