How to import a single table in to mysql database using command line

前端 未结 18 1859
你的背包
你的背包 2020-12-22 15:25

I had successfully imported a database using command line, but now my pain area is how to import a single table with its data to the existing database using command line.

相关标签:
18条回答
  • 2020-12-22 15:58

    First of all, login to your database and check whether the database table which you want to import is not available on your database.

    If it is available, delete the table using the command. Else it will throw an error while importing the table.

    DROP TABLE Table_Name;
    

    Then, move to the folder in which you have the .sql file to import and run the following command from your terminal

    mysql -u username -p  databasename  < yourtable.sql
    

    The terminal will ask you to enter the password. Enter it and check the database.

    0 讨论(0)
  • 2020-12-22 15:58

    From server to local(Exporting)

    mysqldump -u username -p db_name table_name > path/filename.sql;
    mysqldump -u root -p remotelab welcome_ulink > 
    /home_local/ladmin/kakalwar/base/welcome_ulink.sql;
    

    From local to server(Importing)

    mysql -u username -p -D databasename < path/x/y/z/welcome_queue.sql
    mysql -u root -p -D remotelab < 
    /home_local/ladmin/kakalwar/instant_status/db_04_12/welcome_queue.sql
    
    0 讨论(0)
  • 2020-12-22 15:59

    if you already have the desired table on your database, first delete it and then run the command below:

     mysql -u username -p  databasename  < yourtable.sql
    
    0 讨论(0)
  • 2020-12-22 15:59
    • It would be combination of EXPORT INTO OUTFILE and LOAD DATA INFILE

    • You need to export that single table with EXPORT INTO OUTFILE, this will export table data to a file. You can import that particular table using LOAD DATA INFILE

    • Refer doc1 , doc2

    0 讨论(0)
  • 2020-12-22 16:02

    Using a temporary database could be a solution depending on the size of the database.

    mysql -u [username] -p -e "create database tempdb"
    mysql -u [username] -p tempdb < db.sql
    mysqldump -u [username] -p tempdb _table_to_import_ > table_to_import.sql
    mysql -u [username] -p maindb < table_to_import.sql
    
    0 讨论(0)
  • 2020-12-22 16:05

    Importing the Single Table

    To import a single table into an existing database you would use the following command:

    mysql -u username -p -D database_name < tableName.sql
    

    Note:It is better to use full path of the sql file tableName.sql

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