Introduction to PostgreSQL for MySQL Users: Difference between revisions
iwu |
→listing all tables: add Change the password of a user |
||
(2 intermediate revisions by the same user not shown) | |||
Line 29: | Line 29: | ||
postgres=# create database mydb; | postgres=# create database mydb; | ||
postgres=# grant all privileges on database mydb to dbuser; | postgres=# grant all privileges on database mydb to dbuser; | ||
</syntaxhighlight> | |||
== Listing DBs == | |||
You can list the DBs. | |||
MySQL: | |||
<syntaxhighlight lang="mysql"> | |||
mysql> show databases; | |||
</syntaxhighlight> | |||
PostgreSQL: | |||
<syntaxhighlight lang="psql"> | |||
postgres=# \l | |||
</syntaxhighlight> | |||
== selecting a DB == | |||
You can select a DB. | |||
MySQL: | |||
<syntaxhighlight lang="mysql"> | |||
mysql> use mydb; | |||
</syntaxhighlight> | |||
PostgreSQL: | |||
<syntaxhighlight lang="psql"> | |||
postgres=# \connect mydb; | |||
</syntaxhighlight> | |||
After selecting a DB you can go ahead and execute SQL commands. | |||
== listing all tables == | |||
You can list tables in a DB. | |||
MySQL: | |||
<syntaxhighlight lang="mysql"> | |||
mysql> show tables; | |||
</syntaxhighlight> | |||
PostgreSQL: | |||
<syntaxhighlight lang="psql"> | |||
postgres=# \dt | |||
</syntaxhighlight> | |||
== Change the password of a user == | |||
You can list tables in a DB. | |||
MySQL: | |||
<syntaxhighlight lang="mysql"> | |||
mysql> set password for 'dbuser'@'localhost' = password('newpassword'); | |||
</syntaxhighlight> | |||
PostgreSQL: | |||
<syntaxhighlight lang="psql"> | |||
postgres=# alter user "dbuser" with password 'newpassword'; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 16:44, 29 August 2016
Last tested on Ubuntu 16.04.01 LTS (xenial)
Getting into DB console.
MySQL:
$ mysql -uroot -p
PostgreSQL:
$ sudo su postgres
postgres@hydrogen:~$ psql
Creating DB
Creating a database and granting a user complete access.
MySQL:
mysql> create database mydb;
mysql> grant all on mydb.* to dbuser@localhost identified by 'mypass';
PostgreSQL:
postgres=# create user dbuser with password 'mypass';
postgres=# create database mydb;
postgres=# grant all privileges on database mydb to dbuser;
Listing DBs
You can list the DBs.
MySQL:
mysql> show databases;
PostgreSQL:
postgres=# \l
selecting a DB
You can select a DB.
MySQL:
mysql> use mydb;
PostgreSQL:
postgres=# \connect mydb;
After selecting a DB you can go ahead and execute SQL commands.
listing all tables
You can list tables in a DB.
MySQL:
mysql> show tables;
PostgreSQL:
postgres=# \dt
Change the password of a user
You can list tables in a DB.
MySQL:
mysql> set password for 'dbuser'@'localhost' = password('newpassword');
PostgreSQL:
postgres=# alter user "dbuser" with password 'newpassword';
Exiting from DB
Ctrl-D should exit from both.