1

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.

ImSpeakEnglish
  • 97
  • 2
  • 10

3 Answers3

3

Possibly, your user has no permissions to CREATE DATABASE operation. Grant privileges to your user with grant CREATE on *.* to 'user_1'@'localhost'; in MySQL console.

Valkeru
  • 51
  • 3
1

refer to this similar issue

Possible reasons of the issue :

  • collation of your database
  • mysql credentials are invalid
Khadija
  • 297
  • 1
  • 7
  • Thank you, this got me on the right path! I had development environment setup on this system a while ago. Turns out, reinstalling everything multiple times did not reset my database credentials. Finding old ones took some effort, but it works! – ImSpeakEnglish Jun 06 '18 at 16:40
0

Check connection with current credentials. Example for *nix

mysql -uuser_1 -p

When check mysql server's port

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
Alex Komp
  • 21
  • 2