Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

script to dump single record from table in mysql

Tags:

I want to dump single record from mysql table named as table1 for id = 5.

What is mysql query for same?

I think we can use mysqldump but i have used it with full records of table. But how to use it with single record?

like image 306
Poonam Bhatt Avatar asked Jan 19 '11 10:01

Poonam Bhatt


People also ask

How do I export a single row in MySQL?

SELECT a single row from the source instance, save it in a variable in the script. Then form an INSERT command to execute against the destination instance. This may not be the most efficient way to move a large amount of data, but for a single row it would be fine.

How do I dump a specific table in MySQL?

On the Object Select > Tables to Export tab, select the sakila schema. 3. Under Export Options, select Export to Dump Project Folder if you want database tables to be stored to separate . sql files or Export to Self-Contained File to store the database dump in a single .

What is single transaction in Mysqldump?

Mysqldump with Transactions The --single-transaction flag will start a transaction before running. Rather than lock the entire database, this will let mysqldump read the database in the current state at the time of the transaction, making for a consistent data dump.

What is MySQL dump command?

Mysqldump is a command-line utility that is used to generate the logical backup of the MySQL database. It produces the SQL Statements that can be used to recreate the database objects and data. The command can also be used to generate the output in the XML, delimited text, or CSV format.


2 Answers

if you check at http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html you will find --where option which is the one you need.

Below follows what is stated in that reference:

--where='where_condition', -w 'where_condition'

Dump only rows selected by the given WHERE condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.

Examples:

--where="user='jimf'"
-w"userid>1"
-w"userid<1"
like image 116
Shakti Singh Avatar answered Sep 23 '22 22:09

Shakti Singh


I just would like to post a more explicit answer. This is complementary to the accepted one.

mysqldump -uremote_user -premote_password -hdatabase_host remote_database_name remote_table_name --where='id=1234' --skip-add-drop-table --no-create-info
like image 29
Tk421 Avatar answered Sep 22 '22 22:09

Tk421