psql vs. mysql shell command cheatsheet

2024-12-05
MySQL Postgres
list databases SHOW DATABASES \l
change to a database USE <db_name> \c <db_name>
list tables SHOW TABLES \dt
describe a table DESC <table_name> \d <table_name>
show the create table sql SHOW CREATE TABLE <table_name> pg_dump -st <table_name> <db_name>
explain a query EXPLAIN <sql_statement> EXPLAIN <sql_statement>
expanded(vertical) display \G \gxor use \x to switch
get help ? <SQL STATEMENT>HELP <SQL STATEMENT> \h <SQL STATEMENT>
get active processes SHOW [FULL] PROCESSLIST; SELECT pid, usename, state, query, query_start, application_name FROM pg_stat_activity WHERE state = ‘active’;
kill a process KILL <pid>; SELECT pg_terminate_backend(<pid>);
quit shell QUIT \q