1

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
    Stupid question, but are you sure the database really exists? Maybe that's why the connection is refused and why it's not shown in phpmyadmin. Have you tried connecting to mysql from the command line and run a query like `SHOW DATABASES;` – dbrumann Feb 20 '20 at 05:56
  • I’ve tried to connect to mysql and it turns out to show the message above. Previously, I have successfully connect to mysql and create the database. I’m sure the database is exist because when I create the database with doctrine:database:create, it shows that the database is created succesfully. But when I check the phpmyadmin page, the database is not there. – Samuel Matthew Feb 20 '20 at 16:29
  • @dbrumann I've open mysql via phpmyadmin and run the code `SHOW DATABASES;`. The database `symfony-project` is not there. – Samuel Matthew Feb 20 '20 at 17:01
  • Try password "null" (Don't use quotes) – utkarsh2k2 Feb 21 '20 at 13:12

2 Answers2

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.

Clarity
  • 194
  • 3
  • 15
  • Thanks for the answer. I've tried to create a new database and it's still showing the same message. Right now, I cannot create and drop any databases at all. By the way, I'm using Symfony 4 and my root user password is empty. – Samuel Matthew Feb 20 '20 at 16:35
  • How do I check the password for my user? What I know is i don't have any password for my user. Sorry for my basic knowledge. – Samuel Matthew Feb 20 '20 at 16:51
  • Whoops, just found that you actually can't https://stackoverflow.com/questions/4371/how-do-i-retrieve-my-mysql-username-and-password. But you can reset it according to the instructions following the answers in that question. – Clarity Feb 21 '20 at 05:39
1

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