![](/img/trans.png)
[英]SQLSTATE[HY000] [2005] Unknown MySQL server host ' ' (2) in Laravel
[英]Laravel + MySQL + SSL-Mode - SQLSTATE[HY000] [3159]
在 Linode 上,我設置了一個 MySQL 數據庫集群和一個 Ubuntu 服務器,帶有 Apache 和 Z2FEC392304A5C2BAC14。
當我 SSH 到 Ubuntu 服務器上時,我能夠連接到集群:
mysql --host=lin-xxx-mysql-primary-private.servers.linodedb.net --user=xxx --password --ssl-mode=required
但是,當我運行php artisan migrate
時,我收到以下錯誤:
Illuminate\Database\QueryException
SQLSTATE[HY000] [3159] Connections using insecure transport are prohibited while --require_secure_transport=ON. (SQL: select * from information_schema.tables where table_schema = xxxrch and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
我沒有設置其他答案引用的任何證書/pem 文件,但它仍然適用於 mysqlclient。
我會在我的.env
中添加什么到config\database.php
以使其正常工作?
這是我解決這個問題的方法:
resources\certificates
中在config/database.php
我添加了:
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => extension_loaded('pdo_mysql') && env('APP_ENV') !== 'testing' && env('APP_ENV') !== 'local' ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => resource_path('certificates/certificate.crt'),
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => true,
]) : [],
需要注意的重要一件事是,這不適用於phpunit
測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.