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.
问题:
回答1:
Linux :
In command line
mysql -u username -p databasename < path/example.sql
put your table in example.sql
Import / Export for single table:
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 thecreate table
sql command to create tabletableName
.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 tabletableName
. All theinsert
statements will be executed and the data will be loaded.
回答2:
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
回答3:
All of these options are fine, if you have the option to re-export the data.
But if you need to use an existing SQL file, and use a specific table from it, then this perl script in the TimeSheet blog, with enable you to extract the table to a separate SQL file, and then import it.
回答4:
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 the sql file tableName.sql
回答5:
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.
回答6:
It works correctly...
C:\>mysql>bin>mysql -u USERNAME DB_NAME < tableNameFile.sql
please note .sql file specified your current database..
回答7:
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
回答8:
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
回答9:
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
回答10:
It would be combination of
EXPORT INTO OUTFILE
andLOAD 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 usingLOAD DATA INFILE
Refer doc1 , doc2
回答11:
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 ;
回答12:
mysql -u root -p -D dbname < tablename.sql
回答13:
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