You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 6.1连接MariaDB 10.11遇SSL错误:需SSL但服务器不支持

Rails 6.1连接MariaDB 10.11 SSL错误解决方案

问题重现

创建数据库时触发如下错误:

ActiveRecord::ConnectionNotEstablished: TLS/SSL error: SSL is required, but the server does not support it
Caused by:
Mysql2::Error::ConnectionError: TLS/SSL error: SSL is required, but the server does not support it

排查与解决步骤

1. 修正database.yml配置错误与SSL参数

你的development块引用了未定义的*default别名,会导致配置加载异常;同时需针对mariadb-connector-c驱动,明确设置SSL禁用参数(使用字符串值确保解析生效):

修改后的database.yml:

default: &default
  adapter: mysql2
  pool: 25
  socket: /tmp/mysql.sock
  host: localhost
  timeout: 5000
  username: myuser
  password: password
  encoding: utf8mb4
  collation: utf8mb4_unicode_ci
  variables:
    sql_mode: TRADITIONAL
  # 禁用SSL连接
  ssl_mode: 'DISABLED'
  sslverify: false

johndoe_dev: &johndoe_dev
  <<: *default
  database: the_wagon

development:
  <<: *<%= Rails.env.development? ? "#{ENV["USER"]}_dev" : "ai_dev" %>

2. 确认MariaDB服务器SSL状态

登录MariaDB命令行检查服务器SSL启用情况:

mysql -u myuser -p

执行SQL命令:

SHOW VARIABLES LIKE '%ssl%';

若have_ssl值为NO,说明服务器未启用SSL,需确保客户端配置完全匹配这一状态。

3. 重新安装mysql2 gem(适配mariadb-connector-c)

通过mariadb-connector-c安装的mysql2 gem可能默认强制SSL,需重新安装并明确禁用SSL:

  • 卸载现有gem:
    gem uninstall mysql2
    
  • 重新安装(指定MariaDB配置路径并禁用SSL):
    gem install mysql2 --with-mysql-config=$(which mariadb_config) --with-mysql-ssl=no
    
  • 若使用Bundle管理依赖,先配置再安装:
    bundle config build.mysql2 --with-mysql-config=$(which mariadb_config) --with-mysql-ssl=no
    bundle install
    

4. 检查MariaDB额外配置文件

你的my.cnf引入了/usr/local/etc/my.cnf.d目录下的配置文件,需确认其中没有强制SSL的设置:

  • 查看目录内配置文件:
    cat /usr/local/etc/my.cnf.d/*.cnf
    
  • 若发现require_secure_transport=ON,修改为require_secure_transport=OFF,然后重启MariaDB服务:
    sudo systemctl restart mariadb
    

5. 测试数据库创建

完成上述配置后,执行数据库创建命令验证:

rails db:create

内容的提问来源于stack exchange,提问作者Wako

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 20:55:11