如题,运行php artisan migrate导入数据库到mysql时,报了错误:
C:\Users\Administrator\Downloads\laravel9.38.0>php artisan migrate
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at C:\Users\Administrator\Downloads\laravel9.38.0\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▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
1 C:\Users\Administrator\Downloads\laravel9.38.0\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2 C:\Users\Administrator\Downloads\laravel9.38.0\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel", "root", "", [])
这种问题实际上是php中没有配置mysql插件导致的。php连接mysql的驱动程序有两种:MySQLi 和 PDO,你只需要在配置文件php.ini中将它启用,由于上面的报错是没有启用PDO扩展导致的,这里将“;extension=pdo_mysql”一行前面的分号去掉即可。