博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在macOS上安装PostgreSQL
阅读量:2511 次
发布时间:2019-05-11

本文共 3803 字,大约阅读时间需要 12 分钟。

The following instructions to install PostgreSQL are based on macOS.

以下有关安装PostgreSQL说明基于macOS。

For Windows and Linux, go to and choose your package.

对于Windows和Linux,请访问然后选择您的软件包。

Also search “how to install postgres on windows” or “how to install postgres on your linux distribution” if you’re using other platforms.

如果使用其他平台,也请搜索“如何在Windows上安装postgres”或“如何在your linux distribution上安装postgres”。

It should not differ a lot, especially past the installation phase.

它应该相差不大,尤其是在安装阶段之后。

On macOS we’ll use . If you don’t have Homebrew installed yet, go to and follow the instructions there.

在macOS上,我们将使用 。 如果尚未安装Homebrew,请转到并按照其中的说明进行操作。

Once you are done, get back and in the command line run:

完成后,返回并在命令行中运行:

brew install postgresql

and after it finished, run:

完成后,运行:

brew services start postgresql

to start PostgreSQL as a daemon, which means it will keep running in the background, listening for connections.

将PostgreSQL作为守护程序启动 ,这意味着它将继续在后台运行,监听连接。

Using Homebrew has the great advantage that any update can be installed by running

使用Homebrew的巨大优势是可以通过运行以下命令安装任何更新

brew upgrade postgresqlbrew postgresql-upgrade-databasebrew services restart postgresql

postgresql is the more complex to pronounce name of PostgreSQL, but they are the same thing. It just embeds SQL in the name. What’s SQL? SQL, pronouced “sequel”, means Structured Query Language, and it’s a special language we use to interact with a relational database.

postgresql是PostgreSQL名称的更复杂的发音,但是它们是同一回事。 它只是将SQL嵌入名称中。 什么是SQL ? SQL,被称为“续集”,表示结构化查询语言,它是一种用于与关系数据库进行交互的特殊语言。

If you’re new to database, it’s a lot of new terms for you! Basically a relational database organizes the data into tables, and provides a way to insert and extract data from those tables. That’s SQL.

如果您不熟悉数据库,那么这对您来说是很多新术语! 基本上,关系数据库将数据组织到表中 ,并提供一种从这些表中插入和提取数据的方法。 那是SQL。

And we’re going to use it soon.

我们将很快使用它。

Right after we log in to PostgreSQL!

在我们登录PostgreSQL之后!

Go back to the command line, and type

返回命令行,然后键入

psql postgres

using psql

This will give you access to the postgres database, which is created by default, with your macOS username. Homebrew automatically created your user at installation.

这将使您可以访问使用默认MacOS用户名创建的postgres数据库。 Homebrew在安装时会自动创建您的用户。

Now that we are into the psql application, we can create a new database:

现在我们进入了psql应用程序,我们可以创建一个新的数据库:

CREATE DATABASE test;

Don’t forget the semicolon ;, because it’s needed by SQL otherwise the command will not run.

不要忘记分号; ,因为SQL需要它,否则该命令将不会运行。

Now in a new line, we switch to this database using

现在在新行中,我们使用

\c test

The prompt will tell something like this:

提示将显示以下内容:

You are now connected to database "test" as user "flaviocopes"..

You are now connected to database "test" as user "flaviocopes".

Now we’re going to create a new table.

现在,我们将创建一个新表。

Use this syntax:

使用以下语法:

CREATE TABLE users (  id SERIAL PRIMARY KEY,  email VARCHAR(255) UNIQUE NOT NULL,  password VARCHAR(255) NOT NULL);

Now if you run this, and no error shows up, you will have the table in the system.

现在,如果运行此命令,并且没有出现错误,则系统中将包含该表。

You can see it by running the command

您可以通过运行命令来查看它

\dt

which will show you the database tables:

这将向您显示数据库表:

If you did any error, you can delete the table by running the command

如果发生任何错误,可以通过运行以下命令删除表

DROP TABLE users

To finally quit psql, run

最后退出psql ,运行

\q

or just type quit.

或者只是键入quit

Now that you know how things work under the hood, I will show you an easier way to work with PostgreSQL, and other databases too: the . It works on macOS, Windows and Linux.

既然您知道事情的 ,我将向您展示一种使用PostgreSQL和其他数据库的更简单方法: 。 它适用于macOS,Windows和Linux。

Connect to the database:

连接到数据库:

specifying the test database name:

指定test数据库名称:

In addition to be able to inspect tables with a Graphical User Interface:

除了能够使用图形用户界面检查表之外:

It also allows us to work with SQL queries, very easily:

它还使我们可以非常轻松地使用SQL查询:

翻译自:

转载地址:http://avqgb.baihongyu.com/

你可能感兴趣的文章
和借钱相关(四)
查看>>
tdh inceptor orc表和hdfs上表目录内文件的关系
查看>>
LeetCode Subsets II
查看>>
LeetCode 369. Plus One Linked List
查看>>
[学习笔记]后缀系列总结
查看>>
UIActionSheet 取消按钮不可点击解决方法
查看>>
PHP中的__set和__get方法
查看>>
ruby对象模型
查看>>
Java 正则表达式
查看>>
性能瓶颈定位整体思路
查看>>
十道海量数据处理面试题与十个方法大总结
查看>>
Archlinux GNOME 3 美化
查看>>
20189320《网络攻防》第五周作业
查看>>
2019.1.18笔记
查看>>
删除了Ubuntu之后,不能正常进入到Win7系统之中的解决办法
查看>>
写一个正则表达式匹配手机号
查看>>
Linux试题
查看>>
TableLock插件
查看>>
java 获取页面中的 a 标签 的 href 实例
查看>>
Knowledge Point 20180305 详解精度问题
查看>>