Export a single row from a database as MySQL

MySQL

Nathan Rambeck has a great simple snippet of how to export a single row from a table however it didn't QUITE do what I needed it to. I needed to export a variable from {variable} as I was working on an update script which pulled data from a variable and into a database schema. I got fed up of re-populating the variable data each time.

Here is my version of Nathan's suggestion:

mysqldump -uUSER -pPASSWORD --compact --no-create-info --where="COLUMN_NAME='FILTER_VALUE'" DB_NAME TABLE_NAME

Values in capitals are variables which you should alter with your own values, for example:

mysqldump -udrupal -pdrupal --compact --no-create-info --where="name='theme_settings'" drupal_d6 variable

This produced a line like this:

INSERT INTO `variable` VALUES ('theme_settings','a:1:{s:21:\"toggle_node_info_page\";b:0;}');

The --compact produces a less verbose output (it doesn't drop or lock the table and skips comments). The --no-create-info stops the dump including SQL to recreate the table.

Comment Icon

1 Comments

The most recent comment was on Mon, 11th Jul 2011 - 18:54

Nice! I like it.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <img> <p>
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You can enable syntax highlighting of source code with the following tags: <code>, <pre>, <bash>, <css>, <html>, <js>, <jquery>, <mysql>, <php>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.