1

According to the resolution of this question...

What is the Symfony firewall doing that takes so long?

...I try to change in the .env file

DATABASE_URL=mysql://root:root@localhost/project

to

DATABASE_URL=mysql://root:root@127.0.0.1/project

to achieve better performance.

But then I get an error:

An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused" at /Users/work/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 112

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • try adding the used port number like `127.0.0.1:3306` and clear the cache. – gp_sflover Jul 30 '18 at 09:35
  • I tested `127.0.0.1:3306` and cleared the cache after but this did not solve the problem – peace_love Jul 30 '18 at 09:39
  • try surrounding the address with double quotes (_as showed in the docs_) like `DATABASE_URL="mysql://root:root@127.0.0.1:3306/project"` (_and clear the cache_) PS: Did that line works before? – gp_sflover Jul 30 '18 at 09:48
  • No, this is also not working. Only thing that is actually working is `DATABASE_URL=mysql://root:root@localhost/project` Are you sure, this is the correct port? – peace_love Jul 30 '18 at 09:56
  • I can't know which port are you using for mysql :-) in fact I wrote "try adding the **used** port" (_3306 is the default one in local dev like, as example, XAMPP_) – gp_sflover Jul 30 '18 at 10:02
  • Ah, yeah, the port was wrong. It is another number. But it is still not working... I think this number 127.0.0.1 is probably wrong too – peace_love Jul 30 '18 at 10:17
  • Perhaps `root` user is allowed to use only `localhost`. Look at user's permission in phpmyadmin – Nikita Leshchev Jul 30 '18 at 10:25
  • There is quite some number of questions related to this issue. What is the value of your `bind_address` parameter in `my.cnf`. And what does your computer resolve `localhost` to? – Jovan Perovic Jul 30 '18 at 10:49
  • Also, this answer https://serverfault.com/a/845155/145904 explains how, from MySQL's perspective, `localhost` and `127.0.0.1` might not be all the same, regardless of DNS configuration... – Jovan Perovic Jul 30 '18 at 10:56

1 Answers1

1

Check the user permissions of the database itself, your user may only be allowed to access via localhost.

SELECT * FROM mysql.user where user = '<username>';

check the host column. If you only get one row back with the host 'localhost' then you could add another with the same details but for the 127.0.0.1 host

CREATE USER '<username>'@'127.0.0.1';
SET PASSWORD FOR '<username>'@'localhost' = PASSWORD('<password>');
FLUSH PRIVILEGES;

The sql is off the top of my head, you might need to double check it.

Phil Rennie
  • 376
  • 1
  • 6