2

How do I upload my MySQL DB to Heroku for use with a PHP app? The only docs I found on Heroku are this:

Using ClearDB with PHP

Connecting to ClearDB from PHP is super easy, and merely requires the parsing of the CLEARDB_DATABASE_URL to get connected, like this:

<?php
  $url=parse_url(getenv("CLEARDB_DATABASE_URL"));

  $server = $url["host"];
  $username = $url["user"];
  $password = $url["pass"];
  $db = substr($url["path"],1);

  mysql_connect($server, $username, $password);

  mysql_select_db($db);
?>

I don't understand how to fill the ClearDB with my data without an SSH connection, or how to create a database or how to connect to it?

1 Answer 1

4

From ClearDB's Developer Center FAQ:

For importing data into your MySQL database, we recommend that you use both the mysql command line client as well as the mysqldump database backup utility.

Assuming you have the connection information available, use the mysql and mysqldump utilities on your local machine to connect directly to ClearDB remotely and import the data. This other SO answer may help: How to copy a Database from one server to another server in PHP?

You can export a database dump with mysql_dump locally, and then given the username/password/host information from heroku config, you can use they mysql utility locally to import to the remote host, so something like this:

$ mysqldump --user=db1user --password=db1pass local_database > db.sql  
$ mysql --host=remote_host --user=db2user --password=db2pass myschema < db.sql
Sign up to request clarification or add additional context in comments.

6 Comments

ok, but it doesn't tell me how to connect to the Heroku DB. The method I know is to SSH to my web host and use mysql and mysqldump. I don't know how to do that with Heroku.
I expanded my answer to hopefully point you in the right direction. You're bypassing Heroku here
You do not need to use SSH in this case because your ClearDB database is accessible from your own computer directly over the internet, not restricted to localhost.
how do I get the value for remote_host(is it with heroku config?) and how do I set the values for db2user and db2pass?
All of these values are in the the CLEARDB_DATABASE_URL config var, that should have been automatically added to your application when you added the ClearDB add-on. $ heroku config | grep CLEARDB_DATABASE_URL The format is username:password@host
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.