常见的关系型数据库有哪些?如何安装和使用Postgres?(中英双语版)

常见的关系型数据库有哪些?如何安装和使用Postgres?(中英双语版)

关系型数据库是各行业数据存储与管理的核心工具,不同数据库各有特点与适用场景。本文通过中英双语对照,先介绍主流关系型数据库,再详细讲解PostgreSQL的安装(以Windows为例)及基础使用方法,帮助你快速上手。

一、常见的关系型数据库(Common Relational Databases)

Relational databases have a wide range of applications, including web development, inventory management systems, healthcare systems, e-commerce applications, and more.

关系型数据库应用广泛,涵盖网页开发、库存管理系统、医疗系统、电商应用等多个领域。

Some of the most common relational databases are MySQL, PostgreSQL, SQLite, and Microsoft SQL Server. Let's learn a little bit about each one of them.

最常见的关系型数据库包括MySQL、PostgreSQL、SQLite和Microsoft SQL Server,以下分别简要介绍:

1. MySQL

MySQL is an open-source relational database management system. It's very popular for web development because it's easy to use, reliable, and efficient for building real-world applications. It also has an active community of developers that support and maintain it.

MySQL是开源关系型数据库管理系统,在网页开发中极受欢迎。它易于使用、可靠性高,且高效适用于构建实际应用,同时拥有活跃的开发者社区提供支持与维护。

2. PostgreSQL

PostgreSQL is officially described as "The World's Most Advanced Open Source Relational Database." It's a free, open source object-relational database system known for its reliability, data integrity, and extensibility. For example, you can define your own data types, custom functions, and write code in different programming languages without re-compiling your database.

PostgreSQL官方被誉为"世界上最先进的开源关系型数据库",是免费的开源对象关系型数据库系统,以可靠性、数据完整性和可扩展性著称。例如,你可以定义自定义数据类型、自定义函数,无需重新编译数据库即可用不同编程语言编写代码。

3. SQLite

SQLite is a free, open source, and lightweight file-based SQL database engine. It's one of the most widely used database engines in the world. SQLite is self-contained and serverless. It's a zero-configuration database, which means that it doesn't require an initial setup process, which is great for getting started quickly.

SQLite是免费、开源且轻量级的基于文件的SQL数据库引擎,是全球使用最广泛的数据库引擎之一。它自包含、无服务器,属于零配置数据库------无需初始设置过程,便于快速上手。

These three databases are free and open source. There are other popular proprietary options too, including Microsoft SQL Server and Oracle database.

上述三种均为免费开源数据库,还有其他流行的专有数据库,包括Microsoft SQL Server和Oracle数据库:

  • Microsoft SQL Server:Microsoft SQL server is a popular relational database management system developed by Microsoft and used in various applications.(微软开发的流行关系型数据库管理系统,适用于多种应用场景。)

  • Oracle database:Oracle database is a scalable relational database management system often used for enterprise applications that require high performance.(可扩展的关系型数据库管理系统,常用于需要高性能的企业级应用。)

二、PostgreSQL的安装步骤(PostgreSQL Installation Steps)

Great. Now that you know more about the different options available, let's see how you can install PostgreSQL.

了解了不同数据库选项后,我们来学习如何安装PostgreSQL。

1. 下载前准备(Pre-download Preparation)

First, you need to go to the official website: https://www.postgresql.org/.

首先,访问官方网站:https://www.postgresql.org/

Once you're there, click on the "Download" button. This will take you to a page where you can select your operating system. If you click on one, you will be taken to the instructions for that OS.

点击"Download"(下载)按钮,进入操作系统选择页面,点击对应系统即可查看安装说明。

We will go through the installation process for the Windows operating system, but the process is similar across operating systems.

以下以Windows系统为例讲解安装流程,其他操作系统步骤类似。

2. 下载安装程序(Download the Installer)

From this page, you can download the installer by clicking on the "Download the installer" link. This will take you to a page where you can choose the version of PostgreSQL you want to install. If you click on the corresponding icon, the download should start.

点击"Download the installer"(下载安装程序)链接,进入版本选择页面,点击对应版本图标即可开始下载。

3. 运行安装程序(Run the Installer)

Then, in your Downloads folder or the folder where you store your downloads by default, you should see the installer. If you double-click on it, you will start the setup process. Click Next.

在默认下载文件夹中找到安装程序,双击启动安装向导,点击"Next"(下一步)。

4. 选择安装目录与组件(Choose Installation Directory & Components)

Choose the directory where PostgreSQL will be installed. You'll see one by default but you can customize it. Then, select the component that you want to install. There are four possible components:

选择PostgreSQL安装目录(默认目录可自定义),然后选择要安装的组件,共四个可选组件:

  • PostgreSQL Server:the database engine itself.(数据库引擎本身。)

  • pgAdmin 4:a user-friendly tool for database management.(用户友好的数据库管理工具。)

  • Stack Builder:a tool for downloading and installing additional PostgreSQL-related software and extensions.(用于下载安装PostgreSQL相关附加软件和扩展的工具。)

  • Command Line Tools:to interact with the PostgreSQL server directly from your terminal. This includes psql, an interactive terminal for executing SQL queries.(用于从终端直接与PostgreSQL服务器交互的工具,包括执行SQL查询的交互式终端psql。)

When you're ready, click Next.

选择完成后点击"Next"(下一步)。

5. 数据存储与超级用户设置(Data Storage & Superuser Setup)

Then, select a directory to store your data. You will see a default path but you can customize this. When you're ready, click Next.

选择数据存储目录(默认路径可自定义),点击"Next"(下一步)。

Now you'll need to enter a password for the database superuser, the user with unrestricted access to all databases and objects. Type in your password, retype it, and then click Next.

输入数据库超级用户密码(超级用户拥有所有数据库和对象的无限制访问权限),重复输入确认后点击"Next"(下一步)。

6. 端口与区域设置(Port & Locale Settings)

Then, select the port number the server should listen on. By default, it's 5432. Then, click Next.

选择服务器监听端口(默认5432),点击"Next"(下一步)。

You'll need to choose a locale for the new database cluster. This is important for the database to interpret locale-sensitive data types. Then, click Next.

选择新数据库集群的区域设置(这对数据库解释区域敏感数据类型很重要),点击"Next"(下一步)。

7. 完成安装(Complete the Installation)

Finally, you'll see a pre-installation summary. Take a moment to review this and click Next. You will need to confirm that you want to start the installation process. If you click Next, the process will start. It should only take a few minutes.

查看安装前摘要,确认无误后点击"Next"(下一步),再次确认启动安装,过程仅需几分钟。

When the process is completed, based on the components that you installed, you may have to choose if you want to launch Stack Builder to download and install additional tools, drivers, and applications. If you decide to launch Stack Builder, you'll see a screen where you can start the installation. Alternatively, you can click Cancel to do this later on.

安装完成后,根据所选组件,可选择是否启动Stack Builder下载附加工具、驱动和应用(也可点击"Cancel"稍后进行)。

Congratulations! Now you have PostgreSQL installed on your computer. The process should be similar for other operating systems.

恭喜!你已在电脑上安装好PostgreSQL,其他操作系统安装流程类似。

三、PostgreSQL的基础使用(Basic Usage of PostgreSQL)

1. 使用pgAdmin管理数据库(Manage Databases with pgAdmin)

Go to your apps and search for pgAdmin, an open source administration and development platform for PostgreSQL that should have been installed if you selected it in the components. Click on pgAdmin 4 to open it.

在应用中搜索pgAdmin(若安装时选择该组件则已安装,是PostgreSQL的开源管理开发平台),点击pgAdmin 4打开。

You'll see an initial loading screen when the application starts. Then, you should see a dashboard where you can start a new server, check your databases, configure pgAdmin, and more. You'll also find helpful links to the documentation.

启动时会显示初始加载界面,随后进入仪表盘,可在此启动新服务器、查看数据库、配置pgAdmin等,还能找到文档的实用链接。

If you click on "Servers" at the top left, you will need to enter the password that you chose during the installation. After entering your password, you should see a screen where you will have access to your databases, including their tables.

点击左上角"Servers"(服务器),输入安装时设置的密码,即可访问数据库及其包含的表。

2. 使用psql执行SQL查询(Execute SQL Queries with psql)

You'll also find another very helpful tool, psql, an interactive terminal for SQL queries. To open it, search for psql on your system. Click on it. It will open the SQL Shell, where you can start running commands.

psql是另一个实用工具------SQL查询交互式终端。在系统中搜索psql并点击打开,将启动SQL Shell,可在此运行命令。

3. macOS下的Homebrew安装方法(Installation via Homebrew on macOS)

Alternatively, if you are installing it on macOS, you can use Homebrew, a package manager. Once you have Homebrew installed, run this command to install PostgreSQL:

若在macOS上安装,可使用包管理器Homebrew。安装Homebrew后,运行以下命令安装PostgreSQL:

brew install postgresql@<version>

You can specify the version that you want to install by writing the number after the at (@) symbol.

在@符号后输入数字可指定要安装的版本。

四、双语测验(Bilingual Quiz)

检验一下你的学习成果吧!欢迎在评论区留下答案~(Test your learning results! Feel free to leave your answers in the comments~)

1. Which of the following is NOT a common relational database?(以下哪项不是常见的关系型数据库?)

  • MySQL

  • Node

  • PostgreSQL

  • SQLite

2. PostgreSQL is known for its:(PostgreSQL以什么著称?)

  • Weak SQL support and limited features.(弱SQL支持和有限功能。)

  • Strong SQL support and powerful features.(强SQL支持和强大功能。)

  • Exclusive use in small systems.(仅用于小型系统。)

  • Small developer community.(小开发者社区。)

3. Which of the following is an open source, lightweight, file-based relational database?(以下哪个是开源、轻量级、基于文件的关系型数据库?)

  • Microsoft SQL Server

  • PostgreSQL

  • SQLite

  • MySQL

相关推荐
愚戏师1 小时前
MySQL SQL 注入
数据库·sql·mysql
q***33374 小时前
UNION 和 UNION ALL 的区别:深入解析 SQL 中的合并操作
数据库·sql·oracle
啊吧怪不啊吧5 小时前
SQL之表的字符串内置函数详解
大数据·数据库·sql
草莓熊Lotso8 小时前
Git 分支管理:从基础操作到协作流程(本地篇)
大数据·服务器·开发语言·c++·人工智能·git·sql
q***333711 小时前
oracle 12c查看执行过的sql及当前正在执行的sql
java·sql·oracle
u***324311 小时前
使用python进行PostgreSQL 数据库连接
数据库·python·postgresql
7***998713 小时前
GaussDB数据库中SQL诊断解析之配置SQL限流
数据库·sql·gaussdb
5***o50016 小时前
PHP在电商中的支付集成
sql·ue5·rizomuv
V***u45317 小时前
如何查看PostgreSQL的版本
数据库·postgresql