EDIT: I have since resolved my issue thanks to this answer https://stackoverflow.com/a/50908912/12296041
I have started learning Symfony for a school project, and I was following a tutorial from Symfony's website, but for some reason, Doctrine doesn't manage to connect to MySQL database I have running on my computer. I'm on a Macbook, using MAMP to run a local MySQL server.Whenever I try to execute any doctrine commands that interact with the database such as php bin/console doctrine:database:create
it never works.
So far, I have checked that I could indeed connect to the database using PHPMyAdmin. I have also tried to change the DATABASE_URL
in the .env
file, but this hasn't solved my issue.I have also tried creating a symbolic link with sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock
but that didn't work either.
This is what my .env
file looks like:
###> doctrine/doctrine-bundle #### Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11"# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yamlDATABASE_URL=mysql://root:root@127.0.0.1:8888/db###< doctrine/doctrine-bundle ###
And I get this error when trying to create a database with doctrine:
In AbstractMySQLDriver.php line 93: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory In PDOConnection.php line 31: SQLSTATE[HY000] [2002] No such file or directory In PDOConnection.php line 27: SQLSTATE[HY000] [2002] No such file or directory
Anything that can point me in the right direction is greatly appreciated, thanks!