如何让mysql2 gem使用新版客户端?

后端开发 2026-07-09

我遇到了一个错误提示

mysql2-0.5.7/lib/mysql2/client.rb:58: warning: Your mysql client library version 5.5.62 does not support setting ssl_mode; full support comes with 5.6.36+, 5.7.11+, 8.0+

但当我查看MySQL版本时

$ mysql --version
mysql  Ver 15.1 Distrib 10.5.29-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

这是一个旧服务器,MySQL 5.5.62可能一开始就存在,但已经很久没更新了。那么,如何让mysql2 gem识别出我的数据库其实比它所认知的版本要新呢?

解决方案

你看到的警告来自 mysql2 这个gem,它在检查它在编译时所使用的客户端库版本——而不是你连接的MySQL/MariaDB服务器版本。

尽管你的服务器是MariaDB 10.5,但该gem链接到了系统上一个较旧的 libmysqlclient(版本5.5.62)。

请确保已安装MariaDB或 MySQL 8+的客户端库:

# For MariaDB (Debian/Ubuntu)
    sudo apt-get install libmariadb-dev

    # Or for MySQL 8+
    sudo apt-get install libmysqlclient-dev

Reinstall the gem so it compiles against the new library

    gem uninstall mysql2
    bundle install

Verify

Run your app again. The warning should be gone once `mysql2` is compiled against `libmysqlclient` 5.6.36+ or the MariaDB equivalent.

**Note:** If you cannot change the system library, you can point the gem to a specific client library path at install time:

    gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章