Connection Setting From Another Server

I want to establish connection in one of my website1 database, how can I establish connection to that database coming from my website2 hosted in different server.

The following is my default connection settings in my website1, Im thinking of changing the **localhost **to something like but the following error is shown

Access denied for user ‘myusername’@‘’ (using password: YES)

$dbservername = “localhost”;
$dbusername = “myusername”;
$dbpassword = “mypassword”;
$defaultdb = “mydatabase”;
$cn = mysql_connect($dbservername,$dbusername,$dbpassword) or die("connection error ".mysql_error());
$db = mysql_select_db($defaultdb);