紀錄在MAC上配合Docker 來使用SQL,並匯入AdventureWorks sample databases 來使用資料
因有感目前工作所在的產品線離外面公司要的東西太遙遠,離職同事分享出去面試時,外面的人都不清楚在做什麼。所以想說在自己電腦上弄個資料庫來學習點東西,也因此產生了今天的主題。
環境準備
透過Docker 官網下載軟體並安裝,接著下載Docker 的image 並且執行在Container
- 安裝Docker.
- Docker下載SQL image
- Docker run

連入資料庫
使用微軟提供的Azure Data Studio 工具連線資料庫。

匯入資料庫
這邊使用AdventureWorks sample databases 在Github 的檔案,並使用instawdbdw.sql 檔案來新增資料庫與資料
第一次執行時,將路徑設定在本機的
/Users/yaosen/Downloads/data-warehouse-install-script/
有正常的新增資料庫、Table等,但卻發現資料表沒有資料,執行結果也沒有顯示錯誤

單獨拉BULK INSERT 出來測試,有跳錯誤訊息。
Cannot bulk load. The file "/Users/yaosen/Downloads/data-warehouse-install-script/DimAccount.csv" does not exist or you don't have file access rights.
因已確定過現在可以存取這個檔案且檔案也存在,Google 查了一下原因
原來是執行過程中,他是吃到Docker 內部的資料夾
首先先取得目前Container 的ID
docker container ls

接下來將檔案複製進去Container
docker cp /Users/yaosen/Downloads/data-warehouse-install-script 4f7130d683c0:/
透過Container 的終端機可以看到檔案已經複製進來

接下來重新執行BULK INSERT 的程式碼,也執行成功

select 資料表內容也有資料

參考資料