问题
I have 2 different webhost (pagodabox
& 000webhost
, both free) and I've set up a localhost
with MySQL.
I've installed wordpress on all three of them which work perfectly fine within their own domain -- ie. when localhost
wordpress is using localhost
database, pagodabox
is using pagodabox
database and so on.
However if I change database access credentials from wp-config.php
in order to, say, make localhost
wordpress connect to 000webhost
database, it doesn't work: "Error establishing database"
.
Here's the respective credentials I use:
<?php
wp-config.php - relevant differences
* members.000webhost.com/panel/Manage MySQL Databases
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '--------_db');
/** MySQL database username */
define('DB_USER', '--------');
/** MySQL database password */
define('DB_PASSWORD', '--------');
/** MySQL hostname */
define('DB_HOST', 'mysq--.000webhost.com');
* tunnel.pagodabox.com
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '--------_db');
/** MySQL database username */
define('DB_USER', '--------');
/** MySQL database password */
define('DB_PASSWORD', '--------');
/** MySQL hostname */
define('DB_HOST', 'tunnel.pagodabox.com');
* localhost
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '--------_db');
/** MySQL database username */
define('DB_USER', '--------');
/** MySQL database password */
define('DB_PASSWORD', '--------');
/** MySQL hostname */
define('DB_HOST', 'localhost');
?>
回答1:
If you have cPanel, and "Remote MySQL" is enabled in your cPanel, then..
You can allow external web servers to access your MySQL databases by adding their domain name to the list of hosts that are able to access databases on your web site.

However I guess you are trying to connect to 000webhost from your local computer. I don't think you can do that because cPanel won't consider it a valid host.
来源:https://stackoverflow.com/questions/16339614/cant-connect-to-mysql-databse-of-any-webhost-from-anywhere-other-than-the-webho