Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1
mysql>  use animals
Database changed
mysql>

The PostgreSQL Command-Line Client


You invoke the PostgreSQL command-line client with the command psql.
As with mysql, you can invoke psql with the name of the database to
which you would like to connect. Also like mysql, psql can take several
options. These options are listed in Table 28.2.


Table 28.2 Command-Line Options to Use When Invoking psql


Option Action

-h
hostname

Connects    to  the remote  host    hostname    (if the database    server  isn’t
located on the local system).

-p n Specifies  n   as  the number  of  the port    that    the client  should  connect
to. Note that this is a lowercase p.

-U
username

Connects    to  the database    as  the user    username.

-W Prompts  for a   password    after   connecting  to  the database.   In
PostgreSQL 7 and later, password prompting is automatic if the
server requests a password after a connection has been established.

-? Displays a   help    message.

Several more options are available in addition to those listed in Table 28.2.
See the psql man page for details on all the available options.


RELATED UBUNTU  AND DATABASE    COMMANDS
The following commands are useful for creating and manipulating
databases in Ubuntu:
createdb—Creates a new PostgreSQL database
createuser—Creates a new PostgreSQL user account
dropdb—Deletes a PostgreSQL database
dropuser—Deletes a PostgreSQL user account
Free download pdf