0
点赞
收藏
分享

微信扫一扫

【大语言模型】15分钟快速掌握LangChain以及ChatGLM

树下的老石头 2023-07-06 阅读 70
postgresql

Vmware

窗口过界:
https://blog.csdn.net/u014139753/article/details/111603882

vmware, ubuntu 安装:
https://zhuanlan.zhihu.com/p/141033713
https://blog.csdn.net/weixin_41805734/article/details/120698714
centos安装:
https://www.cnblogs.com/yoyoblogs/p/10942257.html

1.改时区:
https://blog.csdn.net/Scarlett_OHara/article/details/101269694

2.手动装vmtools:https://kb.vmware.com/s/article/1022525
解压vmtools tar包提示内存不够:
https://blog.51cto.com/u_13372349/5319568 //方法二
报错:https://github.com/vmware/open-vm-tools/issues/521
调整屏幕:https://blog.csdn.net/weixin_55989896/article/details/123308602
参考 https://huaweicloud.csdn.net/63563cdcd3efff3090b5bc47.html 换源,sudo apt-get install open-vm-tools-desktop,成功。

安装mysql 8.0

1.安装mysql(sudo下)
https://www.cnblogs.com/2020javamianshibaodian/p/12920243.html
https://www.sjkjc.com/mysql/install-on-ubuntu/
https://www.51cto.com/article/718700.html
https://devanswe.rs/install-secure-mysql-server-ubuntu-20-04/

# apt update
# apt install mysql-server mysql-client
# systemctl status mysql //验证服务自动启动
# mysql -u root -p //默认root用户连接到mysql

附:手动开启服务:sudo /etc/init.d/mysql start
默认/未经过安全设置时,mysql通过auth_socket验证(root用户)身份,此时未设密码。
登入mysql方式:
未设密码:sudo mysql
设密码后:mysql -u root -p

【PENDING】更改身份验证方法:

ALTER USER 'root'@'localhost' IDENTIFIED WITH

# service mysql status|start|stop|restart:查看mysql状态|启动mysql|停止mysql|重启mysql

安装postgresql 14.8

https://www.myfreax.com/how-to-install-postgresql-on-ubuntu-18-04/

1.安装

# apt-get install postgresql postgresql-client postgresql-contrib

安装完后,postgresql服务自动启动,系统自动生成Postgresql数据库的超级用户postgres——堪比mysql的root用户,密码为空。既是os用户也是db用户。

2.验证安装是否成功:

# sudo -u postgres psql -c "SELECT version();" //用psql工具连接db打印版本
# sudo service postgresql status //或查看状态

3.角色&身份验证

postgresql通过角色处理访问权限。一个角色→一个/一组db用户。
身份验证方法:

  • Trust:只要符合pg_hba.conf的条件,角色无需密码即可连接db。
  • Passwd:密码连接。密码存储方式:scram-sha-256,md5,密码明文。
  • Ident:仅支持TCP/IP连接。通过可选的用户名映射表获取操作端os用户名。
  • Peer:同Ident,但仅支持本地连接。

4.配置文件:

https://www.jianshu.com/p/68be095f983c
https://blog.csdn.net/weixin_47298890/article/details/123380926

A、Postgresql服务器默认只监听本地接口localhost(127.0.0.1)。
修改postgresql.conf,允许对服务器的远程访问:

# vim /etc/postgresql/14/main/postgresql.conf

listen_addresses'*'
在这里插入图片描述

验证是否成功:
# ss -nlt | grep 5432
在这里插入图片描述
√ 正在侦听所有接口。

B、修改pg_hba.conf,使服务端允许认证:

//主机类型 数据库	用户 	源地址	身份验证方法
# TYPE  DATABASE  USER  CIDR-ADDRESS  METHOD

//添加如下一行:(0.0.0.0/0:表示所有源地址)
host  	all		all		0.0.0.0/0		md5

C、【PENDING】
D、重启服务:

# sudo service postgresql restart //或
# sudo /etc/init.d/postgresql restart

5.登录

https://www.cnblogs.com/z-sm/p/5644165.html
https://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgresql.html

成功登入postgres数据库后会显示postgres=#
退出数据库:\q

A、以postgres用户登入:切换用户+psql访问

# sudo su - postgres
~$ psql
//访问与系统用户同名的数据库,db名可省略。常规写法:
//~$ psql -U user -d db -h 127.0.0.1 -p 5432
//-U指定用户,-d指定db,-h指定服务器,-p指定端口。会提示输入用户密码。

在这里插入图片描述
postgres用户通常仅在本地使用。

B、不切换用户:

# sudo -u postgres psql [db名]

在这里插入图片描述

6.创建新角色,新db

A、从终端创建,注:仅超级用户+有CREATEROLE权限的角色可新创建。

# su - postgres -c "createuser user1"
/* # su - postgres -c "createuser user0 --superuser" //指定为超级用户 */
# su - postgres -c "createdb db1"

或:

# sudo -u postgres createuser user1
# sudo -u postgres createdb -O user1 db1 //或
# sudo -u postgres createdb --owner=user1 db1
# sudo -u postgres psql //连接至postgresql shell
postgres=# GRANT ALL PRIVILEGES ON DATABASE db1 TO user1; //赋数据库权限
//若之前未设置密码:
postgres=# \password user1
//改密码:
postgres=# \q
# sudo -u postgres passwd

B、从Postgresql客户端控制台创建:

# sudo -u postgres psql
postgres=# CREATE USER user1 WITH PASSWORD '0000'; //必须是单引号!
postgres=# CREATE DATABASE db1 OWNER user1;
postgres=# GRANT ALL PRIVILEGES ON DATABASE db1 TO user1; //赋数据库权限
//改密码、改角色属性(role attrs):
postgres=# ALTER USER user1 WITH PASSWORD '1111';
postgres=# ALTER USER user1 WITH SUPERUSER CREATEDB CREATEROLE REPLICATION;

指令

postgres=# \du //用户大全
postgres=# \l //db大全
postgres=# \c db1 //切换至数据库db1
postgres=# \c - user1 //切换至用户user1

Bug记

1、切换用户/登录其它用户报错:error: connection to server on socket “/var/run/postgresql/.s.pgsql.5432” failed: fatal: peer authentication failed for user “user1”
参考:
https://stackoverflow.com/questions/17443379/psql-fatal-peer-authentication-failed-for-user-dev
https://gist.github.com/AtulKsol/4470d377b448e56468baef85af7fd614

# vim pg_hba.conf
将文件内如下一行的Method由peer改md5:

在这里插入图片描述

//重启:
# service postgresql restart

在这里插入图片描述
成功。

===
peer→trust the authenticity of UNIX user hence does not prompt for the password.
md5→always ask for a password, and validate it after hashing with MD5.

其它

root改密码:sudo passwd root
清空屏幕:clearreset
退出:q
susu -的区别:https://blog.51cto.com/fuwenchao/1340685

vim

未作更改,退出编辑::q
更改并希望保存:ESC键+:wq
更改但不打算保存:ESC键+:q!

举报

相关推荐

0 条评论