Arch Linux环境下执行Laravel迁移时出现MySQL驱动缺失错误
Arch Linux下Laravel迁移报错:could not find driver(MySQL连接)
执行Laravel数据库迁移时触发以下错误:
Illuminate\Database\QueryException could not find driver (Connection: mysql, SQL: create table migrations` (`id` int unsigned not null auto_increment primary key, migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760 756▕ // If an exception occurs when attempting to run a query, we'll format the error 757▕ // message to include the bindings with SQL, which will make this exception a 758▕ // lot more helpful to the developer instead of just the database's errors. 759▕ catch (Exception $e) { ➜ 760▕ throw new QueryException( 761▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 762▕ ); 763▕ } 764▕ } +29 vendor frames 30 artisan:35 Illuminate\Foundation\Console\Kernel::handle()
已尝试过Manjaro系统下同类问题的解决方案,但未解决问题。
针对Arch Linux的解决方案:
- 安装PHP的MySQL驱动包:
sudo pacman -S php-mysql - 重启PHP相关服务(若使用PHP-FPM):
sudo systemctl restart php-fpm - 验证驱动是否加载:
执行以下命令,若输出包含pdo_mysql、mysqli则说明加载成功:php -m | grep mysql - 检查并启用php.ini中的驱动:
编辑/etc/php/php.ini,取消注释以下两行(若存在):extension=pdo_mysql extension=mysqli - 确保MariaDB/MySQL服务正常运行:
sudo systemctl start mariadb sudo systemctl enable mariadb # 可选,设置开机自启 - 最后重新执行迁移:
php artisan migrate
内容的提问来源于stack exchange,提问作者Boburjon
相关产品推荐
相关产品推荐

