运行php artisan migrate时出现could not find driver异常求助
Laravel迁移报错:could not find driver(MySQL连接)
错误详情
运行php artisan migrate时抛出以下异常:
Illuminate\Database\QueryException could not find driver (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'sistem-inventory' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name) at vendor\laravel\framework\src\Illuminate\Database\Connection.php:829 825▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 826▕ ); 827▕ } ➜ 829▕ throw new QueryException( 830▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 831▕ ); 832▕ } 833▕ } 1 vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65 PDOException
已尝试操作
已在php.ini中取消注释以下两行,但错误仍未解决:
extension=pdo extension=pdo_mysql
解决方案
- 确认修改的是CLI环境的php.ini:PHP的CLI和Web环境可能使用不同的配置文件,运行
php --ini命令查看当前CLI使用的php.ini路径,确保修改的是该文件。 - 检查扩展文件是否存在:
- Windows系统:确认
ext/php_pdo_mysql.dll文件存在于PHP安装目录的ext文件夹中,若缺失需重新下载对应PHP版本的扩展包。 - Linux系统:通过包管理器安装MySQL扩展,比如Ubuntu/Debian执行
sudo apt install php-mysql,CentOS/RHEL执行sudo yum install php-mysqlnd。
- Windows系统:确认
- 重启相关服务:修改php.ini后,需重启Web服务器(Apache/Nginx)或PHP-FPM,CLI环境需关闭终端重新打开,确保配置生效。
- 验证扩展加载状态:运行
php -m命令,检查输出列表中是否包含pdo_mysql,若存在则说明扩展加载成功,否则继续排查配置或文件问题。 - 检查PHP版本兼容性:确保使用的pdo_mysql扩展与当前PHP版本匹配,避免因版本不兼容导致加载失败。
内容的提问来源于stack exchange,提问作者NyK
相关产品推荐
相关产品推荐

