pedram shabani
pedram shabani

Reputation: 1680

Connect to Database Symfony 4 Flex

I am using Symfony 4 Flex.I using this tutorial . This is my my database connection information database_host: 127.0.0.1 database_user: root database_password: null

At first i install Doctrine

composer require doctrine maker

and then i set my database connection information:

 parameters:
       env(DATABASE_URL): 'mysql://root:[email protected]:3306/sona'
    doctrine:
        dbal:
            driver: 'pdo_mysql'
            server_version: '5.7'
            charset: utf8mb4
            url: '%env(resolve:DATABASE_URL)%'
            url: '%env(resolve:DATABASE_URL)%'

When I execute the

php bin/console   doctrine:database:create

I have this error

 In AbstractMySQLDriver.php line 103:

      An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)


    In PDOConnection.php line 47:

      SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)


    In PDOConnection.php line 43:

      SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)


    doctrine:database:create [--shard SHARD] [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction]
    [-e|--env ENV] [--no-debug] [--] <command>

Where is my mistake?

Upvotes: 3

Views: 2768

Answers (2)

Aryashree Pritikrishna
Aryashree Pritikrishna

Reputation: 351

Please update the below configuration in .env file then run the " php bin/console doctrine:database:create" so it will create the database.

# .env (or override DATABASE_URL in .env.local to avoid committing your changes)
# customize this line!
DATABASE_URL="mysql://db_user:[email protected]:3306/db_name"

# to use sqlite:
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/app.db"

Ref : https://symfony.com/doc/current/doctrine.html#installing-doctrine

Upvotes: 0

Make changes in .env file that is located in the root directory of your project.

Upvotes: 1

Related Questions