我已经开始为一个学校项目学习Symfony,并且正在遵循Symfony网站上的教程,但是由于某种原因,Doctrine无法设法连接到我在计算机上运行的MySQL数据库。我在Macbook上,使用MAMP运行本地MySQL服务器。每当我尝试执行任何与数据库交互的教义命令(例如php bin/console doctrine:database:create
)时,它都将无法工作。
到目前为止,我已经检查过我是否确实可以使用PHPMyAdmin连接到数据库。我也尝试过更改DATABASE_URL
文件中的.env
,但这并没有解决我的问题。我也尝试过使用sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock
创建符号链接,但这也不起作用。
这是我的.env
文件的外观:
###> 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:[email protected]:5432/db_name?serverVersion=11"
# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://root:[email protected]:8888/pweb2
###< doctrine/doctrine-bundle ###
并且尝试创建具有学说的数据库时出现此错误:
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
非常感谢能将我指向正确方向的任何事情,谢谢!