Import MySQL Tables To Heroku

There are some situations where you need to migrate the table data in the MySQL table on your local or staging server to the Heroku database.

This is very simple to do. Here I show you how.

I’m using the ClearDB MySQL Database add-on of Heroku which you can configure using this link https://devcenter.heroku.com/articles/cleardb#the-complete-tutorial.

Now you have ClearDB setup. You can re-check your settings using:

heroku config

This will output something like:

CLEARDB_DATABASE_URL:  mysql://user:password@xxxxx.cleardb.com/heroku_xxxxx?reconnect=true

Next step is to take a dump of your MySQL database locally:

mysqldump -u user -h hostname -ppassword database_name table_name > file_name.sql

So we have the dump and we have the Heroku config. Finally, we need to import the data to Heroku.
Use the following command to achieve this:

mysql --host=xxxxx.cleardb.com --user=user --password=password --reconnect heroku_xxxxxx < file_name.sql

Now you can check the database to make sure everything is migrated.
That’s it.

Advertisements

4 thoughts on “Import MySQL Tables To Heroku

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s