SSH [SOLVED]: How to restore single specific column from MySQL dump via shell command?

SSH [SOLVED]: How to restore single specific column from MySQL dump via shell command?

Home Forums SSH SSH [SOLVED]: How to restore single specific column from MySQL dump via shell command?

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36909

    Anonymous

    QuestionQuestion

    How to restore only one certain column from a MySQL dump via ssh command?

    To restore whole database it goes like this:

    mysql -u [user] -p[pass] db < db_dump.sql 
    

    But I need to restore only a specific column in one of the tables.

    Any suggestions greatly appreciated.

    #36910

    Anonymous

    Accepted AnswerAnswer

    The dump file contains INSERT statements that restore whole rows, not individual columns. So you can’t restore just one column.

    What you can do is restore it to a second database

    mysqladmin -u [user] -p[pass] create db2 
    mysql -u [user] -p[pass] db2 < db_dump.sql 
    

    Then you can get into the SQL environment and copy the one column to the main database on respective rows.

    mysql> UPDATE db.mytable JOIN db2.mytable USING (id)
           SET db.one_column = db2.one_column;
    

    I’m of course making assumptions about the name of your table and column to copy, and the primary key column. But it should serve as a generic example to get you started.

    Source: https://stackoverflow.com/questions/48044755/how-to-restore-single-specific-column-from-mysql-dump-via-shell-command
    Author: Bill Karwin
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.