PostgreSQL Novice must learn Getting Started command summary _postgresql

Source: Internet
Author: User
Tags mysql commands postgresql psql

1, command line login database

There are two ways to execute the psql command directly under the system shell, but to enter the PSQL environment first and then connect to the database. Examples are given below:

(1) Direct login

Execute command: psql-h 172.16.35.179-u username-d dbname, where username is the database user name, dbname is the name of the database to be connected, prompt to enter the password after execution is as follows:

Copy Code code as follows:

Password for user username: (Enter password here)

Enter the password to enter the PSQL environment.

(2) Switching databases

Sometimes you need to switch the database in a psql environment, and then execute the following PSQL command:

Copy Code code as follows:

\c dbname username ServerIP Port

In addition to the database name, other parameters are optional, if you use the default value-as a placeholder

After you execute this command, you are prompted to enter a password.

2. View Help

Psql provides a good online help document, and the total entry command is assist, and you can enter this command to see

Copy Code code as follows:

vsb9=# Help
You are are using Psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution Terms
\h for help with SQL commands
\? For help with Psql commands
\g or terminate with semicolon to execute query
\q to quit

As you can see, the Help for standard SQL commands is separate from the help of Psql-specific commands. Enter \? View the Psql command and find that all psql commands start with \, which is easy to distinguish from standard SQL commands.
3. Common commands
In order to facilitate memory, here the corresponding MySQL commands are listed.
(1) List all the databases
Copy Code code as follows:

Mysql:show databases
Psql: \l or \list

(2) Switching databases
Copy Code code as follows:

Mysql:use dbname
Psql: \c dbname

(3) List the data tables under the current database
Copy Code code as follows:

Mysql:show tables
Psql: \d

(4) List all fields of the specified table
Copy Code code as follows:

Mysql:show columns from table name
Psql: \d TableName

(5) View the basic situation of the specified table
Copy Code code as follows:

Mysql:describe TableName
Psql: \d+ tablename

(6) Exit Login
Copy Code code as follows:

Mysql:quit or \q.
Psql:\q

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.