Still Life

A Series of Mental Snapshots

Exporting and Importing An Individual MySQL Table

Posted by Steve on April 21, 2009

In moving databases from development to production it is sometimes necessary to export individual tables so that they can be imported into another database.

Exporting the Table
To export the table run the following command from the command line:
“mysqldump -p - -user=username dbname tableName > tableName.sql”

This will export the tableName to the file tableName.sql.
[NOTE: there should be no space between the two dashes, but I have to write it that way so that it display properly].

Importing the Table
To import the table run the following command from the command line:
mysql -u username -p -D dbname < tableName.sql

The path to the tableName.sql needs to be prepended with the absolute path to that file. At this point the table will be imported into the DB and you are ready to go!

I ran into this issue when attempting to add new tables to my database. I am unable to run the “LOAD DATA INFILE” command, that I had previously used to populate tables, because Webfaction does not give the permission to run the command. Therefore the simplest solution was to export a table from the MySQL database on my personal machine and then import it to the database on the Webfaction server, using the export/import commands seen above.

Hope this helps someone out with exporting individual tables and as always if any clarification is needed or I missed something feel free to let me know.

–Steve

About these ads

3 Responses to “Exporting and Importing An Individual MySQL Table”

  1. [...] Comments (RSS) « Exporting and Importing An Individual MySQL Table [...]

  2. max said

    Um…stupid but important question – where is this command line accessed from????

    In PHPMyAdmin?

    From my computer’s command prompt?

    From an FTP program?

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

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: