主义:数据库:创建连接被拒绝 [英] doctrine:database:create connection refused

查看:115
本文介绍了主义:数据库:创建连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 bitnami LAMPStack 7.4.6-1 3307端口上运行 MySQL 数据库在最新的Ubuntu上。 Symfony版本5.1.0
当我以root用户身份运行此命令时:

I have bitnami LAMPStack 7.4.6-1 running MySQL database on 3307 port on newest Ubuntu. Symfony version 5.1.0 When I run this command as root user:

root@ubuntu:/opt/lampstack-7.4.6-1/apache2/htdocs/sfcourse# php bin/console doctrine:database:create

我看到的错误是:

[error] Error thrown while running command "doctrine:database:create". Message: "An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused"


In AbstractMySQLDriver.php line 93:

  An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused  


In PDOConnection.php line 31:

  SQLSTATE[HY000] [2002] Connection refused  


In PDOConnection.php line 27:

  SQLSTATE[HY000] [2002] Connection refused

.env文件 DATABASE_URL = mysql:// root:000000 @ localhost:3307 / sfcourse

已编辑:doctrine.yaml文件:

EDITED: doctrine.yaml file:

doctrine:
#    parameters:
#        env(DATABASE_URL): ''
    dbal:
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        url: '%env(resolve:DATABASE_URL)%'

谷歌搜索,但大多数建议是使127.0.0.1作为本地主机

googled but most suggestions are to make 127.0.0.1 as localhost

编辑:
检查 mysql>后,MySQL版本为8.0.20;显示变量,例如%version%;

我可以通过终端以root身份登录到SQL,这是有效的

I can login to SQL via terminal as root, that is working

编辑:我以相同的方式创建了用户测试,可以通过终端登录到MySQL,但是不能通过学说创建数据库。我们处于同一起点。

I created same way user test, can login via terminal to MySQL, but cannot create database via doctrine. We are at the same beginning.

编辑:我将sql端口更改回默认值3306,并以sudo doctrine命令运行。现在出错:

I changed sql port back to default 3306 and running as sudo doctrine command. Error now:

An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for u  
  ser 'db_user'@'127.0.0.1' (using password: YES)

我可以作为db_user连接到MySQL 。如果我将.env中的用户更改为其他用户,错误仍然显示db_user。

I can connect as db_user to MySQL. If I change user in .env to other, error still says db_user.

编辑:这是相同的问题驱动程序中发生了异常:SQLSTATE [HY000] [1045]用户'db_user'@'localhost'的访问被拒绝(使用密码:是),但是答案很愚蠢,他安装了所拥有的东西。

this is same question An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES) but answer is dumb, he installed what he had.

推荐答案

在您的学说中。 yaml文件删除这些行

In your doctrine.yaml file remove these lines

    parameters:
        env(DATABASE_URL): ''

根据当前的该学说的symonfy文档 doctrine.yaml文件中没有参数

According to the current symonfy documentation for doctrine there is no parameters in the doctrine.yaml file.

server_version 使我有些头疼。我用这行代码修复了它

The server_version caused some headaches for me. I fixed it with this line

server_version: 5.7.9

查找服务器版本

通过控制台连接到数据库,它将立即向您指出版本

Connect to your database via console, it will state you the version right away

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.27-standard MySQL Community Edition - Standard (GPL)

否则

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------------------+
| Variable_name           | Value                                    |
+-------------------------+------------------------------------------+
| protocol_version        | 10                                       |
| version                 | 5.0.27-standard                          |
| version_comment         | MySQL Community Edition - Standard (GPL) |
| version_compile_machine | i686                                     |
| version_compile_os      | pc-linux-gnu                             |
+-------------------------+------------------------------------------+
5 rows in set (0.04 sec)

这篇关于主义:数据库:创建连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆