Skip to content

Instantly share code, notes, and snippets.

@kamipo
Created May 27, 2020 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamipo/7806543df5917b08bd598b9d884aa93a to your computer and use it in GitHub Desktop.
Save kamipo/7806543df5917b08bd598b9d884aa93a to your computer and use it in GitHub Desktop.
PostgreSQL 101
```bash
brew install postgresql
pg_config
mkdir -p /usr/local/var/postgres
initdb /usr/local/var/postgres -E utf8
vi /usr/local/var/postgres/postgresql.conf
postgres -D /usr/local/var/postgres
# or
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log stop
tail -F /usr/local/var/postgres/server.log
createuser --help
createuser -h 127.0.0.1 -s -r postgres
psql --help
psql -U postgres
```
### postgresql command for mysql users
* show databases;
* ¥l
* select * from information_schema.schemata;
* use dbname
* ¥c dbname
* show tables;
* ¥dt
* ¥z
* show table status from dbname;
* select * from information_schema.tables where table_schema='artest_mysql_development';
* show create table [dbname.]tblname;
* ### postgresql ###
* select * from information_schema.columns
where table_catalog = 'dbname'
and table_name = 'accounts' order by ordinal_position;
* ### mysql ###
* select * from information_schema.columns
where table_schema = 'dbname'
and table_name = 'accounts' order by ordinal_position;
* show full columns from [dbname.]tblname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment