資料庫中匯出表中相應欄位到指定檔案中

2021-09-23 19:35:52 字數 988 閱讀 1165

資料庫中匯出某乙個表中需要的字段到檔案中是公司中經常要做到的事,那怎麼實現呢?

比如你要查詢enterpriseaics中的所有欄位的值到d盤的aa.txt中去,注:aa.txt不能存在,否則會報錯。

[sql]view plain

copy

print

?"font-size:18px;"

>

select

* from

enterpriseaics 

into

outfile 

'd:\\aa.txt';

當然如果你想規範一下格式,例如:每個欄位的值之間以逗號分開,每一行換行,每個欄位的值要引號引起來。那麼就要加上下面的一段話:

[sql]view plain

copy

print

?select

* from

enterpriseaics 

into

outfile 

'd:\\aa.txt'

fields terminated 

by','

enclosed 

by'"'

;  

當然,這是在本地資料庫中匯出的,那麼在本地通過securecrt連線linux資料庫要匯出資料時就要指明匯出路徑了,不然會報沒有寫許可權的錯誤。

[sql]view plain

copy

print

?select

* from

enterprisetype 

into

outfile 

'/var/lib/mysql/enterprisetype.txt'

fields terminated 

by','

enclosed 

by'"'

;  

本人親測,這個/var/lib/mysql路徑可以匯出資料

資料庫中匯出資料到HDFS

sqoop import m 1 connect jdbc mysql 主機ip 3306 資料庫名 username 使用者名稱 password 使用者密碼 table 表名 columns name,age where age 18 target dir 存在hdfs上的表名 delete t...

從資料庫中匯出資料

首先開啟xp cmdshell許可權 exec sp configure show advanced options 1 reconfigure exec sp configure xp cmdshell 1 reconfigure 1,匯出資料到txt exec master.xp cmdshel...

mysql匯出指定欄位或指定資料到檔案中

使用mysqldump把mysql資料庫的資料匯出到檔案中還是挺方便的 比如說要匯出baijunyao資料庫 mysqldump u使用者名稱 p 資料庫名 表名 匯出的檔名 mysqldump uroot p baijunyao baijunyao.sql bash copy 匯出baijunya...