问题(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 配置,确认:
- 服务器启用的 SSL/TLS 协议版本
- 服务器使用的加密算法
- 服务器证书是否有效
更安全的长期解决方案
如果服务器确实需要 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 连接
- 点击 "Advanced" 选项卡,找到userSSL字段,将其参数改为false。
- 点击 "General" 选择卡,在 "URL" 字段中,找到连接字符串,在连接字符串末尾添加参数:
?useSSL=false
。完整的 URL 示例:jdbc:mysql://xx.xx.xx.xx:3306/your_database?useSSL=false