Under Mac, you can use homebrew to install PostgreSQL directly:
| 1 |
brew installpostgresql -v |
For a moment, PostgreSQL will be installed. Next is the initial database, execute the command at the terminal, and initially configure PostgreSQL:
| 1 |
initdb /usr/local/var/postgres-E utf8 |
The above specifies that "/usr/local/var/postgres" is the configuration data for PostgreSQL directory, and setting the database data encoding is UTF8, more configuration information can be "Initdb--help" view.
Set to boot PostgreSQL:
| 12 |
ln-sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgentslaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist |
Start PostgreSQL:
| 1 |
pg_ctl -D /usr/local/var/postgres-l /usr/local/var/postgres/server.log start |
Turn off PostgreSQL:
| 1 |
pg_ctl -D /usr/local/var/postgresstop -s -m fast |
Create a PostgreSQL user
| 123 |
createuser username -P#Enter password for new role:#Enter it again: |
The above username is the user name, enter the user password 2 times after the user creation is complete. More user-created information can be viewed "CreateUser--help".
Create a database
| 1 |
createdb dbname -O username -E UTF8 -e |
The above creates a database named dbname, and specifies that username is the owner of the database (owner), the database Encoding (encoding) is UTF8, and the parameter "-e" means the command that performs the operation of the database is displayed.
More database creation information can be viewed "createdb--help".
Connecting to a database
| 1 |
psql -U username -d dbname -h 127.0.0.1 |
Install PostgreSQL under Mac