mysql,命令匯入\匯出表結構或資料

來源:互聯網
上載者:User

標籤:

在命令列下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

 

mysql,命令匯入\匯出表結構或資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.