使用学说创建数据库时访问被拒绝,Symfony 4

Access denied when creating database with doctrine, Symfony 4

我创建了一个新的 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

什么都试过了,似乎没有任何效果。任何帮助将不胜感激。

参考这个similar issue

问题的可能原因:

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

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

示例
mysql -uuser_1 -p

检查mysql服务器端口时

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

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