mysql,命令导入\导出表结构或数据

在命令行下mysql的数据导出有个很好用命令mysqldump,它的参数有一大把,可以这样查看: 
mysqldump

最常用的: 
mysqldump -uroot -pmysql databasefoo table1 table2 > foo.sql

这样就可以将数据库databasefoo的表table1,table2以sql形式导入foo.sql中,其中-uroot参数表示访问数据库的用户名是root,如果有密码还需要加上-p参数

C:\Users\jack> mysqldump -uroot -pmysql sva_rec date_drv > e:\date_drv.sql

mysql的数据导入也是相当便捷的,如: 
mysql -uroot databasefoo < foo.sql

这样就可以将foo.sql的数据全部导入数据库databasefoo

1.导出整个数据库

  mysqldump -u用户名 -p密码  数据库名 > 导出的文件名 
  C:\Users\jack> mysqldump -uroot -pmysql sva_rec  > e:\sva_rec.sql

  2.导出一个表,包括表结构和数据

  mysqldump -u用户名 -p 密码  数据库名 表名> 导出的文件名 
  C:\Users\jack> mysqldump -uroot -pmysql sva_rec date_rec_drv> e:\date_rec_drv.sql

  3.导出一个数据库结构 
  C:\Users\jack> mysqldump -uroot -pmysql -d sva_rec > e:\sva_rec.sql

4.导出一个表,只有表结构

  mysqldump -u用户名 -p 密码 -d数据库名  表名> 导出的文件名 
  C:\Users\jack> mysqldump -uroot -pmysql -d sva_rec date_rec_drv> e:\date_rec_drv.sql

  5.导入数据库

  常用source 命令 
  进入mysql数据库控制台, 
  如mysql -u root -p 
  mysql>use 数据库 
  然后使用source命令,后面参数为脚本文件(如这里用到的.sql) 
  mysql>source d:wcnc_db.sql

==============

To export

If it's an entire DB, then:

$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql

If it's all DBs, then:

$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql

If it's specific tables within a DB, then:

$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql

You can even go as far as auto-compressing the output using gzip (if your DB is very big):

$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz

If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):

$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql

To import

Type the following command to import sql data file:

$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

In this example, import 'data.sql' file into 'blog' database using Sathish as username:

$ mysql -u sat -p -h localhost blog < data.sql

If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:

$ mysql -u username -p -h 202.54.1.10 databasename < data.sql

OR use hostname such as mysql.cyberciti.biz

$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql

If you do not know the database name or database name is included in sql dump you can try out something as follows:

$ mysql -u username -p -h 202.54.1.10 < data.sql

Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

If you want a GUI tool then you could probably use SQLyog

上一篇:POJ 2549 二分+HASH


下一篇:基于Caffe的Large Margin Softmax Loss的实现(中)