zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

termux安装和配置postgresql和mysql

2023-06-13 09:17:26 时间

mysql:

#安装
apt install mariadb
#打开一个新窗口运行mysql服务
mysqld &
#切换回当前窗口,初始化数据库,设置密码
mariadb-secure-installation
#登录测试
mysql -uroot -p你的密码

pgsql:

#安装
apt install postgresql
#创建指定的数据库目录
mkdir $PREFIX/var/lib/postgresql
#初始化数据库
initdb $PREFIX/var/lib/postgresql
#启动数据库服务
pg_ctl -D $PREFIX/var/lib/postgresql -l logfile start
#启动客户端测试
psql -d postgres

centos7安装pgsql12

执行 : yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y 2:安装postgres

  1. 更新源
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
  1. 安装 先查看postgresql源
yum list | grep postgresql

如果能找到,再执行安装

yum install postgresql12-contrib postgresql12-server -y
  1. 初始化数据库
/usr/pgsql-12/bin/postgresql-12-setup initdb
  1. 设置开机启动
sudo systemctl start postgresql-12
sudo systemctl enable postgresql-12.service
  1. 登录postgresql并设置密码 postgresql在安装时默认添加用户postgres 设置密码
alter user postgres with password '123456';
  1. 设置外网访问,修改两个配置文件
# 1.pg_hba.conf
vim /var/lib/pgsql/12/data/pg_hba.conf
# 文件末尾加入
host    all             all             ::1/128                 md5

# 2.postgresql.conf
# listen_addresses = 'localhost'
# 修改为listen_addresses = '*'来
  1. 重启pgsql systemctl restart postgresql-12

pgsql用户基本

创建数据库

CREATE DATABASE testdb;

创建用户

CREATE USER testuser CREATEDB LOGIN PASSWORD 'testpassword';
将testdb所有权限赋给用户testuser
GRANT ALL ON DATABASE testdb TO testuser;

删除数据库

drop database testdb;

删除用户

drop role testuser;