資料庫 資料的匯入與匯出

2021-10-06 08:54:37 字數 1124 閱讀 8965

一:準備匯入/匯出的基礎環境

1)建立乙個新的目錄,並修改許可權(預設的實在/etc/lib/mysql/)目錄下

mkdir	/myload

chown mysql /myload

2)檢視並修改系統變數

(在資料內的命令內一下用》 表示在資料內的輸入內容)

>show variable like "secure_file_priv"

;]vim /etc/my.cnf

【mysql】

secure_file_priv=

"/myload" //指定資料庫讀取目錄;

二:資料打匯入

·字段分割符要與檔案一致

·表字段型別和字段個數要與檔案匹配

·匯入資料時指定摁鍵的絕對路徑

匯入注意事項

字段分割符要與檔案一致

表字段型別和字段個數要與檔案匹配

匯入資料時指定檔案的絕對路徑

預設只要root使用者有資料匯入許可權

需要提前在資料庫內把要 導到的表內 的表結構建立好

語法:>load data infile 「目錄名/檔名」 

into table 庫名.表名

fields terminated by 「分割符」 //指定列的分隔符

lines terninated by 「\n」; //指定行的分割符 預設行的結尾 \n

三:資料匯出

格式1:select into outfile  「目錄名/檔名」;

格式2:select into outfile 「目錄名/檔名」

fields terminated by 「分隔符」; //指定列的分割符

格式3:select into outfile 「目錄名/檔名」

fieldes terminated by 「分割符」

linex terminated by 「\n」;

匯出資料注意事項

匯出資料行數由sql 查詢決定

匯出的是表記錄 不包括欄位名

自動建立儲存資料的檔案

儲存資料檔案 具有唯一性

匯入匯出資料庫

1.匯出整個資料庫 mysqldump u 使用者名稱 p 資料庫名 匯出的檔名 2.匯出乙個表 mysqldump u 使用者名稱 p 資料庫名 表名 匯出的檔名 3.匯入資料庫 mysql 資料庫名 檔案 mysql u root 資料庫名 檔案 4.備份時,排除某張表的 mysqldump u...

資料庫匯入匯出

啥 也不說了。資料的匯出 1 將資料庫 test 完全匯出 使用者名稱 system 密碼manager 匯出到d daochu.dmp中 exp system manager test file d daochu.dmp full y 2 將資料庫中 system 使用者與sys 使用者的表匯出 ...

資料庫匯入匯出

檢視檔案位置 select from dba directories 建立 create or replace directory my dir as usr datapump create or replace directory my logdir as usr logs 匯出單個例項 expd...