3

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:null@127.0.0.1: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?

pedram shabani
  • 1,654
  • 2
  • 20
  • 30
  • You didn't follow the tutorial. It tells you to edit the .env file to edit the db connection info – JimL Mar 06 '18 at 18:17
  • hi.where is my .env file???I can not find – pedram shabani Mar 06 '18 at 18:19
  • It should be in your project dir, same dir as composer.json – JimL Mar 06 '18 at 18:27
  • i have not this.so i must create this .it is right ???https://symfony.com/doc/current/components/dotenv.html – pedram shabani Mar 06 '18 at 18:28
  • 1
    Nope. If you used symfony create-project symfony skeleton then .env will have been made. It is a . file so it's possible that you just not seeing it. ls -la might reveal it. http://symfony.com/doc/current/configuration/external_parameters.html And the error message shows that you do have a .env file. That is where the 'db_user' string is coming from. – Cerad Mar 06 '18 at 18:30
  • thank you so much.My IDE don't show it for me..I find it finally – pedram shabani Mar 06 '18 at 18:40

2 Answers2

1

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

0

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:db_password@127.0.0.1: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