Search code examples
mysqlsymfonydoctrinesymfony4

Access denied when creating database with doctrine, Symfony 4


I created a new Symfony 4 project and want to create a new database. I'm following this tutorial but can't get it to work. When running

php bin/console doctrine:database:create

I always get the same error:

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)

Following the tutorial, I configured database url in .env file, but it doesn't seem to change anything.

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

My config/packages/doctrine.yaml configuration:

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

Tried everything and nothing seems to work. Any help would be greatly appreciated.


Solution

  • refer to this similar issue

    Possible reasons of the issue :

    • collation of your database
    • mysql credentials are invalid