This article describes three methods for connecting to your Cloud Database:
From a terminal window, use ssh to log into a Cloud Server that's been created in the same region as your Cloud Database. Here's an example ssh command:
ssh user@IPaddress
On your server, use the MySQL client (or a similar tool) to access the database. For MySQL, use this command and paste the hostname string following the -h option:
mysql -h hostname_string -u database_instance_username -p
This section provides a sample script at the end of the section that creates a very simple webpage. You can use this webpage to test that your MySQL database is alive and well. You can also use it as a very simple calculator. Copy / paste the script into a text editor. Then modify the script with your own hostname, user, password, and database name information and save the changes. Copy the script to your Cloud Server, and execute the script to display the simple webpage and test your connection to your database.
Your web server will need to be in the same region as your Cloud Database (i.e. able to connect to the database via the cloud private network).
Note: this assumes that you already have your web server and PHP configured properly.
Copy / paste the script at the end of this section
Copy the Instance Hostname
Paste the Instance Hostname into the text editor
$THE_HOST = "5c70345ad036fc112dc0a14ee1db7992f5c172db.rackspaceclouddb.com";
5c70345ad036fc112dc0a14ee1db7992f5c172db.rackspaceclouddb.com
Modify the information in the script to specify your database user, password, and database name
$THE_USER = "fmdb_readonly";
$THE_PWD = "fmdb_readonly";
$THE_DB = "FEATUREMANIA";
<FORM ACTION='clouddatabases.php' METHOD='POST'>
Copy the modified script and execute it on your Cloud Server
PHP Script: COPY-PASTE THIS SCRIPT (and replace with your own HOST, DB, USER and PWD values)
<html>
<head><title>Connecting to Cloud Databases</title></head>
<body><pre>
<?php
// phpinfo();
$THE_HOST = "5c70345ad036fc112dc0a14ee1db7992f5c172db.rackspaceclouddb.com";
$THE_USER = "fmdb_readonly";
$THE_PWD = "fmdb_readonly";
$THE_DB = "FEATUREMANIA";
//
// Get "e"
//
$arg_expr = trim($_POST["e"]);
if($arg_expr == "") {
$arg_expr = "PI()";
}
else {
if(get_magic_quotes_gpc()) {
$arg_expr = stripslashes($arg_expr);
}
//
// Connect to the database
//
$connection = mysql_connect($THE_HOST, $THE_USER, $THE_PWD);
if (!$connection) {
die('I could not connect to the database. The error is: ' . mysql_error());
}
mysql_select_db($THE_DB, $connection);
//
// Calculation
//
$result = mysql_query("SELECT (" . $arg_expr . ");", $connection);
$row = mysql_fetch_array($result, MYSQL_NUM);
$eValue = $row[0];
printf("The database connection worked, and MySQL says that %s = %s<BR>%s", $arg_expr, $eValue, mysql_error());
mysql_free_result($result);
mysql_close($connection);
}
?>
<FORM ACTION='clouddatabases.php' METHOD='POST'>
Enter a MySQL expression:
<INPUT TYPE="TEXT" NAME="e" VALUE="<? echo $arg_expr; ?>"/>
<INPUT TYPE="SUBMIT">
</FORM>
This is a simple PHP example to test your connection to Rackspace Cloud Databases.
It does not require your database to have any tables.
It doubles as a handy way to calculate simple MySQL expressions from the browser.
<BR>
Because this sample uses string concatenation to compose SQL statements, only use this in your development environment in your password-protected site.
<BR>
EXAMPLES:
PI()*3*3
curdate()
3=3 AND 4>4
MID('Rackspace',1,4)
SIN(PI()/2)
SHA1('Rackspace Cloud Databases')
</pre></body>
</html>
Note: This Cloud Load Balancer should only be used to access your Cloud Database. Do not add other nodes to the load balancer.
Copy the Instance Hostname
Create a Load Balancer for the Instance
The Cloud Load Balancer is created and your Cloud Database is now accessible through the load balancer.
Note: Using a Cloud Load Balancer to access your database instance incurs normal load balancing and bandwidth charges. For more information, see Cloud Load Balancers Pricing and Calculator.
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

8 Comments
Having trouble connecting?
phpMyAdmin
re: phpMyAdmin
What is the advantage of
re: LB
I'm not sure about the replication, myself. I'll try to find out.
How about scaling the cloud database?
Also right now there are no caching mechanism provided by Rackspace which is the important need.
would be great if someone can enlighten on these aspects.
Monitoring Performance
Connecting with GUI
Add new comment