2

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:[email protected]: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.

1

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

refer to this similar issue

Possible reasons of the issue :

  • collation of your database
  • mysql credentials are invalid

1 Comment

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!
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';

Comments

0

Try to replace localhost for 127.0.0.1 in your .env(or other .env.*) file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.