升级到 laravel 5.8 后数据库访问错误

DB access error after upgrade to laravel 5.8

我使用 laravelshift 一次将 laravel 从 5.3 升级到 5.8,并测试了每个升级,例如

但是当我在服务器上部署它时,Linode 服务器设置了 Cpanel,并且我在该网站的 Mutiphp 管理器中 select php7.2。

现在这在 homestead 的本地环境中完美运行,但在现场我收到数据库错误“用户 'homestead'@'localhost' 的访问被拒绝(使用密码:YES)”。

我还尝试使用 mysql 命令行工具连接到数据库,并且它使用相同的密码。我还更改了 cpanel 中的密码并尝试使用新密码。没有任何效果。

您的服务器中可能没有名为 homestead 的数据库。先创建数据库再尝试连接。

我第一次使用mariadb时遇到了同样的问题,也许,这篇文章保留了您问题的解决方案。

看这里:https://superuser.com/questions/603026/mysql-how-to-fix-access-denied-for-user-rootlocalhost

将密码更改为更简单的密码,例如只有数字和数字字符,没有像 #( 等特殊字符对我有用。

包含特殊字符的复杂密码在命令行中使用 mysql 工具对我有用,但是当我 运行 php artisan install 或 运行 我的时候会出错浏览器中的代码 http://my-project.dev

尽管 OP 通过使用不带特殊字符的密码找到了解决方案,但此问题的真正原因是 Laravel 5.8 使用了新的 phpdotenv 包,该包将 # 符号视为开始的评论。

来自 Laravel 5.8 升级指南。

the # character in an unquoted value will now be considered a comment instead of part of the value.

To preserve the previous behavior, you may wrap the environment values in quotes: