*.sql文件導入資料庫通常比較方便。 其他格式如csv、xsl等文件導入比較費勁。 推薦一個針對csv\xsl的導入工具:https://github.com/zhengze/file_to_db.git 如果文件第一行是table的欄位名,自動建表+導入數據,實在是省事。 具體用法請看READM ...
*.sql文件導入資料庫通常比較方便。
其他格式如csv、xsl等文件導入比較費勁。
推薦一個針對csv\xsl的導入工具:https://github.com/zhengze/file_to_db.git
如果文件第一行是table的欄位名,自動建表+導入數據,實在是省事。
具體用法請看README:
load data from csv/xlsx into database(mysql/postgresql)
INSTALL
pipenv install #或者
pip install -r requirements.txt
CONFIG
- $sudo touch .env
DATABASE_URI=postgresql+psycopg2://admin:1234@localhost/test
USAGE
python file_to_db.py -h
usage: file_to_db.py [-h] [--file FILE] [--table TABLE]
optional arguments:
-h, --help show this help message and exit
--file FILE, -f FILE the file path.
--table TABLE, -t TABLE
the table name.
示例:
python file_to_db.py -f user -t ./test.csv
test.csv內容如下:
name,age zhangsan,15