Read more

PostgreSQL cheat sheet for MySQL lamers

Thomas Eisenbarth
September 26, 2013Software engineer at makandra GmbH

So you're switching to PostgreSQL from MySQL? Here is some help...

General hints on PostgreSQL

  • \? opens the command overview
  • \d lists things: \du lists users, \dt lists tables etc

Command comparison

Description MySQL command PostgreSQL equivalent
Connect to the database mysql -u $USERNAME -p sudo -u postgres psql
Show databases SHOW DATABASES; \l[ist]
Use/Connect to a database named 'some_database' USE some_database; \c some_database
Show tables/relations within one database SHOW TABLES; \dt
Show table details (columns, types) DESCRIBE some_table; \d+ some_table
Show indices of some_table (in case of MySQL) and all indices of database (PostgreSQL) SHOW INDEX FROM some_table; \di
Create user that can create databases CREATE USER harry IDENTIFIED BY 'foo'; CREATE ROLE username WITH createdb LOGIN [PASSWORD 'password'];
Change password of an existing user ... ALTER ROLE username WITH PASSWORD 'password';
Grants access to a database. GRANT ALL PRIVILEGES ON database.* TO username@localhost; GRANT ALL PRIVILEGES ON DATABASE database TO username;
Grants access to create databases. ? ALTER USER username CREATEDB;
Expanded table formatting mode (pretty print) YOUR QUERY\G; \x on

Further reading

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot
Thomas Eisenbarth
September 26, 2013Software engineer at makandra GmbH
Posted by Thomas Eisenbarth to makandra dev (2013-09-26 17:35)