mysql command-line import and export .sql file

Under window

1. Export the entire database
mysqldump -u username -p database name> exported file name
mysqldump -u dbuser -p dbname> dbname.sql

2. Export a table
mysqldump -u username -p database name watches> Export file name
Users -p dbname -u dbuser the mysqldump> dbname_users.sql

3. deriving a database structure
the mysqldump -u -p -d dbuser Table --add-drop-dbname> D: /dbname_db.sql
-d no data --add-drop -table increase before each create a statement Table drop

4. import database
common source command
into the console mysql database, such as
mysql -u the root -p
mysql> use the database
and use the source command, after the parameter is a script file (as used herein with to .sql)
MySQL> D Source: /dbname.sql

 

 

1.  import data into the database

mysql -uroot -D database name 

1.  Import data into a table in the database to obtain

mysql -uroot -D name of the database table names

 

D:\APMServ5.2.6\MySQL5.1\bin>mysqldump -u root -p  erp lightinthebox_tags > ligh
tinthebox.sql

 

Under linux

A derived database using mysqldump command (mysql installation path, i.e. the path of the command):
1, and export the data table structures:
mysqldump -u username -p parameters (optional) database name> / home / sql / database name .sql

mysqldump -u root -p --default-character-set=utf8 db_name>/home/sql/fileName.sql


You will be prompted to enter the password after the knockout round

2, only export the table structure
mysqldump -u username -p password -d database name> database name .sql
# / usr / local / MySQL / bin / mysqldump-uroot--p -d abc> abc.sql

Note: / usr / local / mysql / bin / ---> mysql data directory


Second, the import database
1, the database is first built empty
mysql> create database abc;

2, import database
Method a:
(1) Select Database
MySQL> use ABC;
(2) set the database encoding
MySQL> SET names UTF8;
(. 3) import data (note sql file path)
MySQL> Source / Home / ABC / ABC .sql;
method two:
MySQL -u username -p parameters (optional) database name <database name .sql
#mysql -uabc_f -p-- default-character- SET = UTF8 ABC <abc.sql

Guess you like

Origin www.cnblogs.com/Zhusi/p/11518076.html