ubuntu下用python操作postgresSQL

ubuntu下用python操作postgresSQL

本文记录了在ubuntu系统下用python操作postgresSQL数据库的过程,遇到的问题以及解决方法。
系统版本: Ubuntu 20.04
时间: 2021年3月
数据库版本: 12

1. 安装postgresSQL

按照官网的教程,终端中执行以下命令,这里选择了版本12。

# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
sudo apt-get update

# Install the latest version of PostgreSQL.
sudo apt-get -y install postgresql-12

之后启动服务:

sudo pg_ctlcluster 12 main start

2. 创建数据库

创建数据库首先需要用以下命令切换用户:

sudo -i -u postgres

之后创建数据库:

createdb mydb

进入数据库

psql mydb

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/willian113/article/details/114700062