# PostgreSQL ###### tags: `database` `posthreSQL` ## 安裝 mac使用homebrew安裝 ```bash= $ brew install postgresql ``` 安裝完後啟動方法 ```bash= $ brew services start postgresql ``` 另外可能會有一些local的設定問題 去改 pg_hba.conf METHOD部分全部改成trust ![](https://paper-attachments.dropbox.com/s_255BCCDB78628893F9AFF3D089565885742F21A71090D983A0C76BF3911184A6_1607586112406_+2020-12-10+3.41.11.png) ## 啟動 首先需要先創造DB ```bash= $ createdb <your db name> ``` 創造完後就可以進入操作 ```bash= $ psql -U <your db name> ``` 接下來會進入你的DB內,就可以直接開始操作DB了 ``` <your db name>=$ ``` ## 語法 ### 創造table ``` > CREATE TABLE <table name> ``` ### 刪除table ``` > DROP TABLE <table name> ``` ### 查詢table ``` > SELECT * FROM <table name> ``` [練習的網站](https://www.codecademy.com/learn/learn-sql)