尝试运行Illuminate\Database\QueryException : could not find driver
时,我遇到php artisan migrate
错误。
我环顾四周但找不到这个例外的解决方案。
我在Windows计算机上运行带有PHP 7.2和MySQL 5.7的Laravel 5.6。
这是.env文件:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larabiz
DB_USERNAME=root
DB_PASSWORD=root
还有详细的错误日志:
php artisan migrate -v
Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = larabiz and table_name = migrations)
at C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php: 664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("could not find driver")
C:\Users\Cyril\Projects\larabiz\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php : 47
2 PDOException::("could not find driver")
C:\Users\Cyril\Projects\larabiz\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php : 43
3 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=larabiz", "root", "root", [])
C:\Users\Cyril\Projects\larabiz\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php : 43
4 Doctrine\DBAL\Driver\PDOConnection::__construct("mysql:host=127.0.0.1;port=3306;dbname=larabiz", "root", "root", [])
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 65
5 Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:host=127.0.0.1;port=3306;dbname=larabiz", "root", "root", [])
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 44
6 Illuminate\Database\Connectors\Connector::createConnection("mysql:host=127.0.0.1;port=3306;dbname=larabiz", [])
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connectors\MySqlConnector.php : 24
7 Illuminate\Database\Connectors\MySqlConnector::connect()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php : 183
8 Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Connectors\{closure}()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 915
9 call_user_func(Object(Closure))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 915
10 Illuminate\Database\Connection::getPdo()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 940
11 Illuminate\Database\Connection::getReadPdo()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 399
12 Illuminate\Database\Connection::getPdoForSelect()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 325
13 Illuminate\Database\Connection::Illuminate\Database\{closure}("select * from information_schema.tables where table_schema = ? and table_name = ?")
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 657
14 Illuminate\Database\Connection::runQueryCallback("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 624
15 Illuminate\Database\Connection::run("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 333
16 Illuminate\Database\Connection::select("select * from information_schema.tables where table_schema = ? and table_name = ?")
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Schema\MySqlBuilder.php : 18
17 Illuminate\Database\Schema\MySqlBuilder::hasTable("migrations")
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Migrations\DatabaseMigrationRepository.php : 169
18 Illuminate\Database\Migrations\DatabaseMigrationRepository::repositoryExists()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php : 545
19 Illuminate\Database\Migrations\Migrator::repositoryExists()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php : 97
20 Illuminate\Database\Console\Migrations\MigrateCommand::prepareDatabase()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php : 63
21 Illuminate\Database\Console\Migrations\MigrateCommand::handle()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php : 29
22 call_user_func_array([])
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php : 29
23 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php : 87
24 Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php : 31
25 Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), [])
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Container\Container.php : 564
26 Illuminate\Container\Container::call()
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Console\Command.php : 183
27 Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
C:\Users\Cyril\Projects\larabiz\vendor\symfony\console\Command\Command.php : 252
28 Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Console\Command.php : 170
29 Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
C:\Users\Cyril\Projects\larabiz\vendor\symfony\console\Application.php : 865
30 Symfony\Component\Console\Application::doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
C:\Users\Cyril\Projects\larabiz\vendor\symfony\console\Application.php : 241
31 Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
C:\Users\Cyril\Projects\larabiz\vendor\symfony\console\Application.php : 143
32 Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Console\Application.php : 88
33 Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
C:\Users\Cyril\Projects\larabiz\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php : 121
34 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
C:\Users\Cyril\Projects\larabiz\artisan : 37
感谢您的帮助!
答案 0 :(得分:0)
我在Ubuntu 16.04中有一个类似的问题,对我有帮助的是我为php 7.2安装了php-mysql。如果您拥有php 7.2或根据您的PHP版本安装php mysql,我建议您运行以下命令
apt-get install php7.2-mysql
systemctl restart apache2