您的位置:首页 > 数据库

postgresql for mac简单操作

2016-09-15 18:58 295 查看
frankslgdeMacBook-Pro:~ frankslg$ pg_ctl -D /usr/local/var/postgres/ -l /usr/local/var/postgres/server.log stop


waiting for server to shut down………….. done

server stopped

在关闭的时候一定要注意,如果有服务正在使用postgresql时,stop会关闭失败

frankslgdeMacBook-Pro:~ frankslg$ pg_ctl -D /usr/local/var/postgres/ -l /usr/local/var/postgres/server.log start


server starting

启动成功之后,需要连接数据库(连接之前先查看有哪些库)

frankslg$ psql -l


然后进入:

frankslgdeMacBook-Pro:~ frankslg$ psql msf
psql (9.4.5)
Type "help" for help.

msf=#


使用命令(方法)查看:

msf=# \?
General
\copyright             show PostgreSQL usage and distribution terms
\g [FILE] or ;         execute query (and send results to file or |pipe)
\gset [PREFIX]         execute query and store results in psql variables
\h [NAME]              help on syntax of SQL commands, * for all commands
\q                     quit psql
\watch [SEC]           execute query every SEC seconds

Query Buffer
\e [FILE] [LINE]       edit the query buffer (or file) with external editor
\ef [FUNCNAME [LINE]]  edit function definition with external editor
\p                     show the contents of the query buffer
\r                     reset (clear) the query buffer
\s [FILE]              display history or save it to file
\w FILE                write query buffer to file

Input/Output
\copy ...              perform SQL COPY with data stream to the client host
\echo [STRING]         write string to standard output
\i FILE                execute commands from file
\ir FILE               as \i, but relative to location of current script
\o [FILE]              send all query results to file or |pipe
\qecho [STRING]        write string to query output stream (see \o)
:   #此后还有很多命令


使用“\dt”查看当前库中有哪些表

msf=# \dt
List of relations
Schema |                      Name                      | Type  | Owner
--------+------------------------------------------------+-------+-------
public | api_keys                                       | table | msf
public | automatic_exploitation_match_results           | table | msf
public | automatic_exploitation_match_sets              | table | msf
public | automatic_exploitation_matches                 | table | msf
public | automatic_exploitation_runs                    | table | msf
public | clients                                        | table | msf
public | credential_cores_tasks                         | table | msf
public | credential_logins_tasks                        | table | msf
public | creds                                          | table | msf
public | events                                         | table | msf


之后就和其它数据库的操作一样了:

msf=# select * from api_keys;
id | token | created_at | updated_at
----+-------+------------+------------
(0 rows)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  postgresql mac