skip to Main Content

I accidentally created a database symfony-project successfully, but it’s not appearing on my phpmyadmin page. I want to drop the database with

php bin/console doctrine:database:drop --force

then this message comes out

Could not drop database symfony-project for connection named default
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused

When I try to create a new database, with php bin/console doctrine:database:create, an error message comes out:

In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused

In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] Connection refused

In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] Connection refused

Because the connection is refused, I can’t create and drop any databases right now.

My database url on the .env file is

DATABASE_URL=mysql://root:@127.0.0.1:3306/symfony-project?serverVersion=5.7

My password is empty.

I’ve tried to change the 127.0.0.1 to localhost and the error message is telling me that

there is no such file or directory.

I’m using symfony 4 and xampp on macOS

UPDATE

I’ve edited my config/packages/doctrine.yaml file. I commented the url: '%env(resolve:DATABASE_URL)%' and added this:

doctrine:
dbal:
    dbname: symfony-project
    charset: utf8
    host: 127.0.0.1
    port: 8080
    user: root
    password:
    driver: pdo_mysql

and now this message comes out

In AbstractMySQLDriver.php line 106:
An exception occurred in driver: SQLSTATE[HY000] [2006] MySQL server has gone away

In PDOConnection.php line 31:
SQLSTATE[HY000] [2006] MySQL server has gone away

In PDOConnection.php line 27:
SQLSTATE[HY000] [2006] MySQL server has gone away

In PDOConnection.php line 27:
PDO::__construct(): MySQL server has gone away

2

Answers


  1. I think you can also try the connection by attempt to create a database:

    php bin/console doctrine:database:create
    

    If you’re using Symfony 2, you need to use:

    php app/console doctrine:database:create
    

    I also see that in the string:

    DATABASE_URL=mysql://root:@127.0.0.1:3306/symfony-project?serverVersion=5.7
    

    You didn’t specify the password for root user. Although that might be not an issue if the password is unspecified at the beginning, it’s better to re-check these credentials.

    Login or Signup to reply.
  2. You have to configure your doctrine.yaml

    doctrine:
      dbal:
          dbname:       database
          charset:      utf8
          user:         user
          password:     secret
          driver:       pdo_mysql
    

    Check the documentation : https://symfony.com/doc/current/reference/configuration/doctrine.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search