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

SpringBoot项目连接MariaDB时GSS-API认证异常求助

解决MariaDB GSS-API认证异常问题

出现GSS-API authentication exception: Unable to obtain Principal Name for authentication错误,本质是MariaDB Java客户端默认尝试Kerberos认证,但你的环境未配置Kerberos,导致认证失败。以下是具体解决思路:

1. 强制JDBC连接使用普通密码认证

在JDBC URL中添加参数禁用GSS-API,并指定认证插件:

jdbc:mariadb://<host>:<port>/<db_name>?useGssapi=false&authenticationPlugin=mysql_native_password
  • useGssapi=false:关闭Kerberos认证尝试
  • authenticationPlugin=mysql_native_password:指定使用原生密码认证插件(如果你的用户用的是caching_sha2_password,替换成对应值即可)

2. 修正IntelliJ数据库连接配置

在IntelliJ的数据库连接窗口:

  • 切换到Advanced标签页
  • 找到useGssapi参数,设置值为false
  • 或者直接在URL输入框中添加上述参数,覆盖默认配置

3. 确认MariaDB用户的认证插件

登录MariaDB服务器,执行以下SQL检查用户的认证插件:

SELECT user, plugin FROM mysql.user WHERE user='<your_username>';

如果插件不是mysql_native_password或caching_sha2_password,执行以下命令修改:

ALTER USER '<your_username>'@'%' IDENTIFIED WITH mysql_native_password BY '<your_password>';
FLUSH PRIVILEGES;

(%表示允许远程连接,若仅本地连接可替换为localhost)

4. 调整SpringBoot配置文件

在application.properties或application.yml中明确配置带参数的JDBC URL:

application.properties示例

spring.datasource.url=jdbc:mariadb://localhost:3306/your_db?useGssapi=false&authenticationPlugin=mysql_native_password
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

application.yml示例

spring:
  datasource:
    url: jdbc:mariadb://localhost:3306/your_db?useGssapi=false&authenticationPlugin=mysql_native_password
    username: your_username
    password: your_password
    driver-class-name: org.mariadb.jdbc.Driver

5. 排查客户端版本兼容性

你使用的mariadb-java-client-3.0.6版本默认启用了GSS-API认证尝试,若上述参数无效,可尝试降级到2.x稳定版本(如2.7.6):
Gradle依赖配置:

implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.6'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 23:07:31