How can I copy a single row/record from one MySQL instance to another?

后端 未结 1 642
遥遥无期
遥遥无期 2021-01-18 01:03

I have two MySQL instances running with the same schema. One is in the cloud; one is on my local box. The local-box version needs a couple of test rows in its main table.<

1条回答
  •  -上瘾入骨i
    2021-01-18 01:33

    If you're already familiar with mysqldump, I'll remind you that mysqldump has a --where option, so you can get a single row if you write the condition for that:

    mysqldump databasename tablename --where "id=12345" --no-create-info --skip-add-locks --host=db1  | \
      mysql --host=db2
    

    You could also use SELECT...INTO OUTFILE to dump the result of any query you want into a flat file, even a query of a single row. Then LOAD DATA INFILE to import that file on the other instance.

    You could also write a simple script in your choice of language. Connect to both instances. 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.

    0 讨论(0)
提交回复
热议问题