【发布时间】:2021-12-17 17:02:25
【问题描述】:
我正在尝试在我刚刚创建的新数据库上运行 php artisan migrate。我在连接到 mariadb 时遇到了很多麻烦,但我设法解决了它。现在,每当我尝试连接它时,由于某种原因,我无法输入任何密码或任何密码,但我仍然可以连接到它。我不知道这是否正常。无论如何,我将 laravel 项目中的.env 文件修改为
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=liberty_comerce
DB_USERNAME=root
DB_PASSWORD=
但我收到错误 SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE')。如果我将DB_HOST=127.0.0.1 更改为DB_HOST=localhost,我会收到错误SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE')。
我试过跑步
php artisan config:clear
php artisan config:cache
php artisan cache:clear
每次我改变任何东西。我一直在网上寻找答案,但似乎没有任何效果。
【问题讨论】:
-
我能够通过重新启动 mariadb 服务来修复这些错误,现在我得到了
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE')我尝试了在网上找到的不同解决方案,但没有一个对我有用。而且我仍然可以通过sudo mariadb或sudo mariadb -u root -p连接到mariadb,然后无论我输入什么密码,它都可以使用 -
好的,我发现问题来自这样一个事实,即通过 root 连接到我的 mariadb 的唯一方法是使用
sudo但 laravel 不能使用它。 -
请创建新的数据库用户然后你可以继续它。