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

前端 未结 18 1858
你的背包
你的背包 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:48

    Command Line

    Import / Export for single table:

    Exporting table schema

     -> mysqldump -u your_user_name -p your_database_name table_name > test.sql
    

    This will create a file named test.sql and creates table sql command to create table table_name.

    Importing data into table

     -> mysql -u your_user_name -p database_name table_name < test.sql
    

    Make sure your test.sql file is in the same directory, if not navigate through the path and then run the command.

    0 讨论(0)
  • 2020-12-22 15:48
    -> mysql -h host -u user -p database_name table_name < test_table.sql
    
    0 讨论(0)
  • 2020-12-22 15:52

    It works correctly...

    C:\>mysql>bin>mysql -u USERNAME DB_NAME < tableNameFile.sql
    

    please note .sql file specified your current database..

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

    To import a table into database, if table is already exist then add this line in your sql file DROP TABLE IF EXIST 'table_name' and run command mysql -u username -p database_name < import_sql_file.sql. Please verify the sql file path before execute the command.

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

    Also its working. In command form

    cd C:\wamp\bin\mysql\mysql5.5.8\bin //hit enter
    mysql -u -p databasename //-u=root,-p=blank
    
    0 讨论(0)
  • 2020-12-22 15:58

    Export:

    mysqldump --user=root databasename > whole.database.sql
    mysqldump --user=root databasename onlySingleTableName > single.table.sql
    

    Import:

    Whole database:

    mysql --user=root wholedatabase < whole.database.sql
    

    Single table:

    mysql --user=root databasename < single.table.sql
    
    0 讨论(0)
提交回复
热议问题