我正在尝试执行php artisan migrate命令以在phpmyadmin中创建一个表
但它的显示误差
“找不到司机”
我做了php artisan serve,它成功了
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'testdb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'xxxx'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=xxxx--这是命令行中显示的错误:
Illuminate\Database\QueryException : could not find driver
(SQL: select * from information_schema.tables where table_schema =
testdb and table_name = migrations)
at C:\AppServ\www\laravel2\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 PDOException::("could not find driver")
C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=testdb", "root", "xxxx", [])
C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70它将显示“成功创建的表”,并在phpmyadmin中创建
发布于 2019-04-12 11:47:28
确保mysql在您的计算机上运行,如果您使用的国产mysql端口可能是33060。
要明确mysql是否正在运行,请在mac或linux上打开终端或windows上的命令行,如果遇到错误,则编写mysql -u root,这意味着mysql没有运行。
发布于 2019-04-12 11:53:22
您缺少php-mysql驱动程序,如果缺少它,可以通过执行php -i | grep mysql来检查它,考虑到您的系统类型,您必须安装它,例如,如果您在ubuntu上运行php7.2系统,您应该这样做:sudo apt-get install php7.2-mysql。
发布于 2019-04-12 12:16:07
根据此更改config/database.php文件:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],检查这里:链接
打开.env文件并编辑它。只需设置正确的数据库凭据即可
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username
DB_PASSWORD= // Your Database Password, If no password is set then just clear it在.env编辑之后,必须清除缓存:php artisan config:cache
https://stackoverflow.com/questions/55650725
复制相似问题