IT袋

当前位置:主页 > 经验教程 > 软件教程 >

如何建立自己的数据库文件

如何建立自己的数据库文件 mysql数据库基础知识

更新:2023-08-25 22:48:08 来源:IT袋 作者:苏晓敏
导读:如何建立自己的数据库文件,今天小编详解如何建立自己的数据库文件和mysql数据库基础知识的相关话题,接下来分享详细内容。 PostgreSQL 是最灵活的数据库之一,并且它是开源的。 数据库是以一种有

如何建立自己的数据库文件

今天小编详解如何建立自己的数据库文件和mysql数据库基础知识的相关话题,接下来分享详细内容。

PostgreSQL 是最灵活的数据库之一,并且它是开源的。

数据库是以一种有组织且灵活的方式存储信息的工具。电子表格在本质上就是一个数据库,但是图形化应用程序这一限制使得大多数的电子表格应用程序对程序员毫无用处。随着 边缘计算和物联网设备成为重要的平台,开发者们需要更有效且轻量级的方法,来存储、处理、查询大量的数据。我最爱的一种组合是使用Lua 连接&nbsp

ostgreSQL 数据库。无论你使用什么编程语言,PostgreSQL 一定是数据库的绝佳选择,但是在使用 PostgreSQL 之前,首先你需要知道一些基本的东西。

安装 PostgreSQL

在 Linux 上安装 PostgreSQL,要使用你的软件库。在 Fedora,CentOS,Megeia 等类似的 Linux 版本上使用命令:

$ sudo dnf install postgresql postgresql-server

在 Debian, Linux Mint, Elementary 等类似的 Linux 版本上使用命令:

$ sudo apt install postgresql postgresql-contrib

在 macOs 和 Windows 上,可以从官网 postgresql.org下载安装包。

配置 PostgreSQL

大多数发行版安装 PostgreSQL 数据库时没有启动它,但是为你提供了一个脚本或 systemd 服务,能够可靠地启动 PostgreSQL。但是,在启动 PostgreSQL 之前,必须创建一个数据库集群。

Fedora

在 Fedora,CentOS 等类似的版本上,PostgreSQL 安装包中提供了一个 PostgreSQL 配置脚本。运行这个脚本,可以进行简单地配置:

$ sudo /usr/bin/postgresql-setup --initdb[sudo] password: * Initializing database in '/var/lib/pgsql/data' * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

Debian

在基于 Debian 的发行版上,在安装 Postgres 的过程中,配置会通过apt自动完成。

其他版本

最后,如果你是在其他版本上运行的,那么你可以直接使用 PostgreSQL 提供的一些工具。initdb命令会创建一个数据库集群,但是这个命令必须在postgres用户下运行,你可以使用sudo来暂时地成为postgres用户:

$ sudo -u postgres \ "initdb -D /var/lib/pgsql/data \ --locale en_US.UTF-8 --auth md5 --pwprompt"

运行 PostgreSQL

现在,数据库集群已经存在了,使用initdb的输出中提供给你的命令或者使用 systemd 启动 PostgreSQL 服务器:

$ sudo systemctl start postgresql

创建一个数据库用户

使用createuser命令来创建一个数据库用户。postgres用户是 Postgres 安装的超级用户。

$ sudo -u postgres createuser --interactive --password bogusShall the new role be a superuser? (y/n) nShall the new role be allowed to create databases? (y/n) yShall the new role be allowed to create more new roles? (y/n) nPassword:

相关阅读