首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Laravel + MySQL + SSL-Mode - SQLSTATE[HY000] [3159]

Laravel + MySQL + SSL-Mode - SQLSTATE[HY000] [3159]
EN

Stack Overflow用户
提问于 2022-06-22 11:10:45
回答 1查看 330关注 0票数 0

在Linode上,我使用ApacheandPHP8.1设置了一个MySQL数据库集群和一个Ubuntu服务器。

当我SSH到Ubuntu服务器时,我能够连接到集群:

mysql --host=lin-xxx-mysql-primary-private.servers.linodedb.net --user=xxx --password --ssl-mode=required

但是,当我运行php artisan migrate时,我会得到以下错误:

代码语言:javascript
运行
复制
   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来实现这个工作呢?

EN

Stack Overflow用户

回答已采纳

发布于 2022-08-01 12:54:33

我是怎么解决这个问题的:

dashboard.

  • Place

  • 从Linode resources\certificates

  • 下载证书

config/database.php中,我添加了:

代码语言:javascript
运行
复制
'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测试是行不通的。

这个答案很有帮助:https://stackoverflow.com/a/70468831/1343140

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72714453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档