MySQL資料庫匯入和匯出

來源:互聯網
上載者:User

MySQL資料庫匯入和匯出

MySQL資料中,使用時,總是會碰見匯入和匯出情況,所以如何正確的匯入匯出,非常重要!下面根據工作中用到的方法:

匯入:

直接在Mysql中匯入:

mysql>use databaseName;

mysql> load data infile 'filePath' into table 'tableName'

如果直接使用sql指令檔,可使用source:

進入mysql資料庫控制台,如mysql -u root -p

mysql>use 資料庫

然後使用source命令,後面參數為指令檔(如這裡用到的.sql)

mysql>source d:\wcnc_db.sql

匯出:

從Linux終端或者shell視窗,或者命令提示字元匯出:

mysql [-h IP -P port] -u userName -p Password DatabaseName "select * from tableName [where]" > filePathName

另外可以使用mysqldump,幾個常用用例如下:

1.匯出整個資料庫

mysqldump -u 使用者名稱 -p 資料庫名 > 匯出的檔案名稱

mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql

2.匯出一個表

mysqldump -u 使用者名稱 -p 資料庫名 表名> 匯出的檔案名稱

mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql

3.匯出一個資料庫結構

mysqldump -u wcnc -p -d --add-drop-table smgp_apps_wcnc >d:\wcnc_db.sql

-d 沒有資料 --add-drop-table 在每個create語句之前增加一個drop table

在Mysql中,進行匯出操作:

select * into outfile 'fileName' from tableName [where ...](匯出表中的部分或者全部資料)

--------------------------------------分割線 --------------------------------------

Ubuntu 14.04下安裝MySQL

《MySQL權威指南(原書第2版)》清晰中文掃描版 PDF

Ubuntu 14.04 LTS 安裝 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主從伺服器

Ubuntu 12.04 LTS 構建高可用分布式 MySQL 叢集

Ubuntu 12.04下原始碼安裝MySQL5.6以及Python-MySQLdb

MySQL-5.5.38通用二進位安裝

--------------------------------------分割線 --------------------------------------

本文永久更新連結地址:

相關文章

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.