首页 > 解决方案 > Laravel 无法加载动态库 'pdo_mysql.so'

问题描述

我有一个 Laravel 项目,我需要进行一些维护,所以我克隆了该项目,运行composer update然后尝试迁移php artisan migrate(在 MySQL 上创建数据库之后)...

我在 Ubuntu 20.04 上,使用 PHP 7.4 和 Laravel 8。

我收到此错误:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: undefined symbol: mysqlnd_allocator), /usr/lib/php/20190902/pdo_mysql.so.so (/usr/lib/php/20190902/pdo_mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

   Illuminate\Database\QueryException 

  could not find driver (SQL: select * from information_schema.tables where table_schema = escola_da_qualidade and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:685
    681▕         // If an exception occurs when attempting to run a query, we'll format the error
    682▕         // message to include the bindings with SQL, which will make this exception a
    683▕         // lot more helpful to the developer instead of just the database's errors.
    684▕         catch (Exception $e) {
  ➜ 685▕             throw new QueryException(
    686▕                 $query, $this->prepareBindings($bindings), $e
    687▕             );
    688▕         }
    689▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

在 Stackoverflow 上搜索,我尝试使用 , 等安装apt-get install php-mysqlapt-get install php7.4-mysql...

这是结果php -m

[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
imap
intl
json
libxml
mbstring
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

我也尝试extension=pdo_mysql在 /etc/php/7.4/apache2/php.ini 以及 /etc/php/7.4/cli/php.ini 中取消注释,然后重新启动 apache2,但仍然出现相同的错误。

laravel config/database.php 上的默认驱动程序是'default' => env('DB_CONNECTION', 'mysql'),和 .env 我有DB_CONNECTION=mysql

也试过php artisan config:cachephp artisan config:clear

有什么帮助吗?

标签: laravelpdolaravel-8

解决方案


推荐阅读