MySQL连接报SSL错误

问题(cmd)

bash 复制代码
C:\Users>mysql -h xx.xx.xx.xx -u root -p
Enter password:
ERROR 2026 (HY000): SSL connection error: error:0A000102:SSL routines::unsupported protocol

解决方案

1. 临时禁用 SSL 连接(不推荐生产环境使用)

如果您只是想临时连接到数据库进行测试,可以在连接命令中明确禁用 SSL:

bash 复制代码
mysql -h xx.xx.xx.xx -u root -p --ssl-mode=DISABLED
2. 更新 MySQL 客户端版本

如果您使用的是较旧版本的 MySQL 客户端,可能不支持服务器要求的 SSL/TLS 协议版本。尝试更新到最新版本:

复制代码
# Ubuntu/Debian
sudo apt update
sudo apt upgrade mysql-client

# CentOS/RHEL
sudo yum update mysql

# macOS (使用Homebrew)
brew update
brew upgrade mysql
3. 配置客户端使用特定 SSL 协议版本

可以尝试指定客户端使用特定的 SSL 协议版本:

bash 复制代码
mysql -h xx.xx.xx.xx -u root -p --ssl-cipher=AES256-SHA256 --ssl-mode=REQUIRED
4. 检查服务器 SSL 配置

联系数据库管理员检查 MySQL 服务器的 SSL 配置,确认:

  1. 服务器启用的 SSL/TLS 协议版本
  2. 服务器使用的加密算法
  3. 服务器证书是否有效
更安全的长期解决方案

如果服务器确实需要 SSL 连接,建议获取服务器的 SSL 证书并在客户端使用:

bash 复制代码
mysql -h xx.xx.xx.xx -u root -p \
  --ssl-ca=/path/to/ca-cert.pem \
  --ssl-cert=/path/to/client-cert.pem \
  --ssl-key=/path/to/client-key.pem

问题(IDEA)

bash 复制代码
DBMS: MySQL (ver. 8.2.0)
Case sensitivity: plain=exact, delimited=exact
Driver: MySQL Connector/J (ver. mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c), JDBC4.2)
The server has terminated the handshake. The protocol list option (`enabledTLSProtocols`) is set, this option might cause connection issues with some versions of MySQL. Consider removing the protocol list option in the JDBC driver.

解决方案

IDEA中填写MySQL的Data Sources时(不管有没有密码),生成的URL都是jdbc:mysql://xx.xx.xx.xx:3306/goldgoldgold_2,此时没有禁用SSL,此时为了连接可以禁用SSL。

禁用 SSL 连接
  1. 点击 "Advanced" 选项卡,找到userSSL字段,将其参数改为false。
  2. 点击 "General" 选择卡,在 "URL" 字段中,找到连接字符串,在连接字符串末尾添加参数:?useSSL=false。完整的 URL 示例:jdbc:mysql://xx.xx.xx.xx:3306/your_database?useSSL=false
相关推荐
fengye20716135 分钟前
板凳-------Mysql cookbook学习 (十)
学习·mysql·adb
蓝黑202036 分钟前
使用SSH tunnel访问内网的MySQL
mysql·ssh·proxy
夕泠爱吃糖1 小时前
MySQL中的部分问题(1)
数据库·mysql
百度Geek说1 小时前
Redis 数据恢复的月光宝盒,闪回到任意指定时间
数据库
秃了也弱了。2 小时前
DBSyncer:开源数据库同步利器,MySQL/Oracle/ES/SqlServer/PG/
数据库·mysql·开源
玄辰星君2 小时前
PostgreSQL 入门教程
数据库·postgresql
泽韦德2 小时前
【Redis】笔记|第9节|Redis Stack扩展功能
数据库·redis·笔记
喜欢踢足球的老罗2 小时前
使用 Spring Boot 3.3 和 JdbcTemplate 操作 MySQL 数据库
数据库·spring boot·mysql
文牧之2 小时前
PostgreSQL 的扩展pg_prewarm
运维·数据库·postgresql
行星0082 小时前
Postgresql字符串操作函数
数据库·postgresql