【问题标题】:Access denied when creating database with doctrine, Symfony 4使用学说 Symfony 4 创建数据库时访问被拒绝
【发布时间】:2018-11-16 07:03:20
【问题描述】:

我创建了一个新的 Symfony 4 项目并想创建一个新的数据库。我正在关注this tutorial,但无法正常工作。运行时

php bin/console doctrine:database:create

我总是遇到同样的错误:

In AbstractMySQLDriver.php line 112:
    An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'user_1'@'localhost' (using password: YES)

In PDOConnection.php line 50:
    SQLSTATE[HY000] [1045] Access denied for user 'user_1'@'localhost' (using password: YES)

In PDOConnection.php line 46:
    SQLSTATE[HY000] [1045] Access denied for user 'user_1'@'localhost' (using password: YES)

按照教程,我在 .env 文件中配置了数据库 url,但它似乎没有改变任何东西。

DATABASE_URL=mysql://user_1:secretPassword@127.0.0.1:3306/db_name

我的 config/packages/doctrine.yaml 配置:

parameters:
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

尝试了一切,但似乎没有任何效果。任何帮助将不胜感激。

【问题讨论】:

标签: mysql symfony doctrine symfony4


【解决方案1】:

参考这个similar issue

问题的可能原因:

  • 您的数据库的整理
  • mysql 凭据无效

【讨论】:

  • 谢谢,这让我走上了正确的道路!不久前我在这个系统上设置了开发环境。事实证明,多次重新安装所有内容并没有重置我的数据库凭据。寻找旧的需要一些努力,但它有效!
【解决方案2】:

使用当前凭据检查连接。 *nix 的示例

mysql -uuser_1 -p

查看mysql服务器端口时

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

【讨论】:

    【解决方案3】:

    您的用户可能没有CREATE DATABASE 操作的权限。 在 MySQL 控制台中使用 grant CREATE on *.* to 'user_1'@'localhost'; 向您的用户授予权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 2020-12-07
      • 2016-03-02
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      相关资源
      最近更新 更多