Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Postgres
- ========
- Command to display active connections to a PostgresDB: `SELECT * FROM pg_stat_activity;`
- Connection to Redshift
- ----------------------
- ```
- $ psql -h <ENDPOINT_NAME>.us-east-1.redshift.amazonaws.com -p 5439 -d <DB_NAME> -U <DB_USERNAME>
- password <TYPE_YOUR_PASSWORD_HERE>
- ```
- ```
- \list or \l: list all databases
- \dt: list all tables in the current database
- \dn: list of schemas
- \dt <schema_name>.*: list tables in <schema_name>
- \d+ <schema_name>.<table_name>: describe a table in a schema
- SET search_path = <schema_name>;
- ```
- To find all the columns with a name like query:
- ```
- select table_name, column_name
- from information_schema.columns
- where table_schema=<SCHEMA_NAME> and column_name like '%some%thing%';
- ```
- To see output in VERTICAL form:
- ```
- \x # enable vertical output
- <your queries>
- \x # disable vertical output
- ```
- MySQL
- =====
- Connection
- ----------
- ```
- $ mysql -h <HOST_IP> -P 3306 -u <DB_USERNAME> -p -A -D <DB_NAME>
- <TYPE_YOUR_PASSWORD_HERE>
- ```
- ```
- show databases;
- use <DB_NAME>;
- <YOUR QUERY> \G # the output in VERTICAL form
- ```
- Performing a dump
- -----------------
- ```
- $ mysqldump -P 3306 -h <HOST_IP> -u <DB_USERNAME> -p <DB_PASSWORD> <TABLE_NAME> --where="columns='some_value'" > ~/tmp/foo.sql
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement