You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel执行数据库迁移时出现MySQL权限拒绝错误求助

Laravel执行数据库迁移时出现MySQL权限拒绝错误求助

大家好,我最近在给Laravel项目做数据库迁移的时候碰上个棘手的问题,执行迁移命令后直接报权限拒绝,具体情况如下:

我执行的迁移命令是:

php artisan migrate

返回的完整错误信息:

SQLSTATE[HY000] [1044] Access denied for user 'api'@'localhost' to database 'api' (Connection: mysql, SQL: select * from information_schema.tables where table_schema = api and table_name = migrations and table_type = 'BASE TABLE')

at vendor\laravel\framework\src\Illuminate\Database\Connection.php:801

797▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
798▕                 );
799▕             }
800▕
➜ 801▕             throw new QueryException(
802▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
803▕             );
804▕         }
805▕     }

1   vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65
PDOException::("SQLSTATE[HY000] [1044] Access denied for user 'api'@'localhost' to database 'api'")

2   vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65
PDO::__construct()

我已经尝试过下面两种方法,但都没能解决问题:

  • 用.env文件里的数据库账号密码手动连接MySQL是正常的,能顺利访问目标数据库
  • 已经在php.ini文件中添加了extension=pdo_mysql配置,重启服务后问题依旧

有没有朋友遇到过类似的情况?麻烦给点排查思路或者解决方案,谢谢啦!

备注:内容来源于stack exchange,提问作者ch3tt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 10:33:03