How to import a single table in to mysql database

2019-01-29 17:24发布

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.

标签: mysql import
13条回答
Animai°情兽
2楼-- · 2019-01-29 17:44

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.

查看更多
等我变得足够好
3楼-- · 2019-01-29 17:47
  • 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

查看更多
三岁会撩人
4楼-- · 2019-01-29 17:47
mysql -u root -p -D dbname < tablename.sql
查看更多
Juvenile、少年°
5楼-- · 2019-01-29 17:57

Linux :

In command line

 mysql -u username -p  databasename  < path/example.sql

put your table in example.sql

Import / Export for single table:

  1. Export table schema

    mysqldump -u username -p databasename tableName > path/example.sql
    

    This will create a file named example.sql at the path mentioned and write the create table sql command to create table tableName.

  2. Import data into table

    mysql -u username -p databasename < path/example.sql
    

    This command needs an sql file containing data in form of insert statements for table tableName. All the insert statements will be executed and the data will be loaded.

查看更多
▲ chillily
6楼-- · 2019-01-29 17:57

you can do it in mysql command instead of linux command.
1.login your mysql.
2.excute this in mysql command:
use DATABASE_NAME;
SET autocommit=0 ; source ABSOLUTE_PATH/TABLE_SQL_FILE.sql ; COMMIT ;

查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-29 18:00

We can import single table using CMD as below:

D:\wamp\bin\mysql\mysql5.5.24\bin>mysql -h hostname -u username -p passowrd databasename < filepath
查看更多
登录 后发表回答