Though I can setup an almost same database as another server, I'd like to directly connect to the other server. To do like this, one edit will affect 2 sites. Can we use like this:
hhheng, if the host is in the form of a domain name, it would be something like 'anotherdomain.com' (without 'http://'). Port number is optional if it's the standard 3306. On the network level, you'll need to make sure the firewall doesn't block you, as garbageman suggested. On database level, you may also need to grant the privileges to a user from the location you're connecting from (unless if the the user is already granted the privileges to connect from anywhere, which is not recommended for security reasons). For more info on granting privileges: http://dev.mysql.com/doc/en/GRANT.html
$db_host = "anotherdomain.com:3306" is not working. Actually i have 2 websites run on 2 different servers, and both sites need to connect the same database on one of the server. How to know whether the firewall block outside connection or not?
Try this - $db_host = '192.160.X.X' ; Using the server IP address and the authorized user and password of that database.. Boulder
If the database is on IP2 and you need to connect from IP1, run mysql from IP1 from the command line and connect to IP2. e.g.: mysql -h IP2 -u yourusername -p If it hangs there for a long time and then timeout or gives you an error message saying 'Connection refused' (or something like that), it means it's blocked by the firewall. If you can connect, but when you do 'use yourDbName' it gives you a 'permission denied' error message, then you need to run the 'GRANT' query on IP2. Note: - The error msg may differ significantly. I haven't used MySQL for quite a while so can't really remember anymore. - Copy the error msg that you get here, if you still find problems.
Ask your server admin what teh db host is cause some times its different on the server i use they simply have you put the word mysql as the db host..
You need to configure the MySQL server to accept non-localhost connections, by doing so: GRANT ALL PRIVILEGES ON *.* TO USER@"%" IDENTIFIED BY 'PASS' *.* <- You can change this to a specific database (*.) or a specific table (.*). USER <- Username to connect to the database with. % <- % allows connections from ANY IP. If you want to accept connections from a specfic IP, replace the %. PASS <- Username's password to connect to the database with. I wouldn't really suggest giving a "GRANT ALL PRIVILEDGES" option, perhaps just "insert,update,delete,select" should be fine.