数据库连接遇到的问题总结

804 阅读2分钟

数据库连接常见问题

在通过图形化软件连接数据库的过程中,都会遇到一些奇奇怪怪的问题,在这里一次性将新手可能遇到的问题进行总结,便于新手能够快速的查找处理。

  • 主机无法连接
 message from server: "Host 'xxxxxxx' is not allowed to connect to this MySQL server"

解决:

# 第一步进入mysql mysql -uroot -p 
# 第二步 use mysql;
# 第三步 select user,host from user; 
# 修改 update user set host = '%' where user='root';
# 此时再查看 select user,host from user; 
# 重启mysql生效
  • IDEA 连接云服务器问题
Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

或者 使用navivat出现2003-Can’t connect to MySQL server (10060)错误

原因: 服务器3306端口未对外开放 解决:

//查询3306端口是否对外开放
firewall-cmd --query-port=3306/tcp
//增加3306端口
firewall-cmd --add-port=3306/tcp --permanent
  • IDEA连接SQL Server报错
[08S01] 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]”。 ClientConnectionId:272392ee-1272-4622-928d-f8e0f9e1a335 The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]

解决:

修改文件C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\conf\security\java.security

将:jdk.tls.disabledAlgorithms 中的TLSv1,3DES_EDE_CBC删除
  • 测试数据库连接
DBMS: Microsoft SQL Server (ver. 10.50.1600) Case sensitivity: plain=mixed, delimited=mixed Driver: Microsoft JDBC Driver 10.2 for SQL Server (ver. 10.2.0.0, JDBC4.2) Ping: 51 ms SSL: no

TLSv1 was negotiated. Please update server and client to use TLSv1.2 at minimum.

解决:

  1. idea 中的 Project Structure 的SDKs 选择jdk1.8
  2. 其中Project的SDK选择1.8
  • MySQL 默认情况下最大可执行的SQL大小为4M
# 设置最大可执行SQL大小
set global max_allowed_packet=10*1024*1024