mysql command-line export and import data

Export database (sql script) 

mysqldump -u username -p database name> exported file name
mysqldump -u root -p --databases db_name> test_db.sql ## to get the entire database, the most comprehensive ;; do not --databases also OK, that is not enough comprehensive information

Exporting a mysql database table


mysqldump -u username -p database name watches> Export file name
mysqldump -u wcnc -p test_db users> test_users.sql ## ( no semicolon at the end) to give students a database table in my_10, simple

mysql import sql file

1, enter MySQL: mysql -u username -p
  command input line: mysql -u root -p (enter the same after MySQL will let you enter the password)
2, you have to build a new database in MySQL-Front, which when an empty database, such as a new target database, called the news (may be error, do not care for him)
  enter: mysql> use the target database name
  input command line: mysql> use news;
3, import the file: mysql> source import the source file name; 
  input command line: mysql> source news.sql;

 

The following excerpt from http://www.cnblogs.com/yuwensong/p/3955834.html  

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
mysqldump -u dbuser -p dbname users> dbname_users.sql

3. Export a database structure

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

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 script file (such as used herein .sql)
mysql> source D: /dbname.sql


Under linux

A derived database using mysqldump command (mysql installation path, i.e. the path of the command):
1, export the data structures and tables:

mysqldump -u username -p password database name> database name .sql
# / usr / local / MySQL / bin / mysqldump-uroot--p abc> abc.sql
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, import the database
1, first build an empty database

mysql>create database abc;

2, import database
Method a:

(1) Select Database
MySQL> ABC use;
(2) set the database encoding
MySQL> SET UTF8 names;
(. 3) import data (note that the file path sql)
MySQL> Source /home/abc/abc.sql;

Method Two:

mysql -u username -p password database name <database name .sql
#mysql -uabc_f -p abc <abc.sql

Guess you like

Origin www.cnblogs.com/piwefei/p/11468902.html