Can't connect to MySQL databse of any webhost

2019-03-04 04:33发布

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条回答
干净又极端
2楼-- · 2019-03-04 04:55

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.

Remote MySQL in cPanel

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.

查看更多
登录 后发表回答