Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Problemas ao conectar com o banco de dados.

Olá,

Estou tendo problemas ao executar o código mostrado na aula:

curl http://localhost:3000/pagamentos/pagamento -X POST -v -H "Content-type: application/json" -d '{
    "forma_de_pagamento":"payfast",
    "valor":10.99,
    "moeda":"BRL",
    "descricao":"Criando paagamento"    
}' | json_pp

A saída que recebo é essa:

Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1:3000...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /pagamentos/pagamento HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.68.0
> Accept: */*
> Content-type: application/json
> Content-Length: 118
> 
} [118 bytes data]
* upload completely sent off: 118 out of 118 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 113
< ETag: W/"71-JyqJSIoqKIsI205nPxMI6k8DwRI"
< Date: Thu, 13 Aug 2020 18:35:40 GMT
< Connection: keep-alive
< 
{ [113 bytes data]
100   231  100   113  100   118    753    786 --:--:-- --:--:-- --:--:--  1540
* Connection #0 to host localhost left intact
{
   "address" : "127.0.0.1",
   "code" : "ECONNREFUSED",
   "errno" : "ECONNREFUSED",
   "fatal" : true,
   "port" : 3306,
   "syscall" : "connect"
}

e no lado do servidor, a saida no terminal é essa:

processando uma requisicao de um novo pagamento
Erro ao inserir no banco:Error: connect ECONNREFUSED 127.0.0.1:3306

Suspeitei que o problema fosse a inicialização do MySql no localhost, então instalei o MySql Workbench e o status que tenho lá é de "Server status: Stopped". Já tentei "/etc/init.d/mysql start" e a saida foi

Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!

e já tentei também "service mysql start" e a saida foi

Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.

Já procurei em diversos fóruns na internet, mas nada resolveu meu problema.

Já tentei reinstalar o MySql server, também utilizei os comandos para remover a senha pois estava dando acesso negado quando tentava fazer alguma requisição:

UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
exit;

Obrigado.

2 respostas

Neste site fala que tem que ser root para dar um start/stop no mysql.

sudo /etc/init.d/mysql start

https://askubuntu.com/questions/82374/how-do-i-start-stop-mysql-server

solução!

Já havia tentado isso também, consegui resolver acesando o mysql -u root como sudo e usando o seguinte comando, deixando em branco o password:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

mysql> FLUSH PRIVILEGES;

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software