[Kali_Metasploit]db_connect创建连接时无法连接的解决方案

问题1复现路径:

  1. 终端输入msfconsole,进入msf命令行模式,需要等待若干分钟;

  2. 输入db_status,查看连接状态,两种结果:一,默认连接msf3;二,没有连接,显示postgresql selected, no connection

  3. 创建连接数据库msfbook,输入 db_connect postgres:toor@127.0.0.1/msfbook

现象:

  没有显示任何信息,输入db_status查看,仍没有连接

分析:

  没有相关账号和密码,所以无法连接

解决方案:

  1. 在#命令行模式下,输入sudo -u postgres psql postgres // 来创建账号

  2. 就会进入到postgres=#模式下,在msfconsole模式下输入 alter user postgres with password 'toor'; // 来修改密码

  3. 显示ALTER ROLE // 修改生效

  4. 退出postgres=#模式,重新输入db_connect postgres:toor@127.0.0.1/msfbook,就会出现一堆冗长的信息,这是创建连接数据表的过程,这只有在第一次创建postgres的msfbook库时出现冗长信息,以后就没有了,直接回到msf终端提示符。

提示:

  记得开始进入msfconsole前,启动postgresql和metasploit服务,命令如下:

    1. service postgresql start

    2. service metasploit start

 

问题2现象:

  根据以上的步骤进行创建连接数据库后,msf中会提示,创建时数据库编码错误,"Error while running command db_connect: Failed to connect to the database: PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template.: CREATE DATABASE "msfbook" ENCODING = 'utf8' Call stack:......"

分析:

  默认数据库编码问题

解决方案:

  1. sudo -u postgres psql postgres // 进入postgres用户PostgreSQL数据库模式中

  2. 输入 create database msfbook with encoding='SQL_ASCII';

  3. 显示 CREATE DATABASE // 创建成功

 

转载于:https://www.cnblogs.com/webapplee/p/4072701.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值