java.sql.SQLInvalidAuthorizationSpecException:用户'root'@'10.24.1.77'的访问被拒绝(使用密码:是)

时间:2019-05-27 15:33:38

标签: mysql zipkin

我正在kubernetes中运行mysql和zipkin。 Zipkin无法连接到mysql数据库。

我已经检查了环境变量,并且所有变量都已正确设置。

例外

java.sql.SQLInvalidAuthorizationSpecException: Access denied for user 'root'@'10.24.0.00' (using password: YES)
        at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:238) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:171) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1128) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:560) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:174) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.Driver.connect(Driver.java:92) ~[mariadb-java-client-2.4.1.jar!/:?]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.3.1.jar!/:?]
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353) ~[HikariCP-3.3.1.jar!/:?]
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) ~[HikariCP-3.3.1.jar!/:?]
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) [HikariCP-3.3.1.jar!/:?]
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562) [HikariCP-3.3.1.jar!/:?]
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) [HikariCP-3.3.1.jar!/:?]
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) [HikariCP-3.3.1.jar!/:?]
        at zipkin2.storage.mysql.v1.DataSourceCall.doExecute(DataSourceCall.java:55) [zipkin-storage-mysql-v1-2.12.9.jar!/:?]
        at zipkin2.Call$Base.execute(Call.java:379) [zipkin-2.12.9.jar!/:?]
        at zipkin2.reporter.AsyncReporter$BoundedAsyncReporter.flush(AsyncReporter.java:286) [zipkin-reporter-2.8.1.jar!/:?]
        at zipkin2.reporter.AsyncReporter$Builder$1.run(AsyncReporter.java:190) [zipkin-reporter-2.8.1.jar!/:?]
Caused by: java.sql.SQLException: Access denied for user 'root'@'10.24.0.00' (using password: YES)
Current charset is US-ASCII. If password has been set using other charset, consider using option 'passwordCharacterEncoding'
        at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.authentication(AbstractConnectProtocol.java:847) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.handleConnectionPhases(AbstractConnectProtocol.java:752) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connect(AbstractConnectProtocol.java:412) ~[mariadb-java-client-2.4.1.jar!/:?]
        at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1124) ~[mariadb-java-client-2.4.1.jar!/:?]
        ... 14 more

mysql-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
    tier: db
spec:
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        imagePullPolicy: Always
        envFrom:
        - secretRef:
            name: mysql-secrets
        ports:
        - name: client
          containerPort: 3306
        volumeMounts:
        - name: mysql-data
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-data
        persistentVolumeClaim:
          claimName: mysql-claim

mysql-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: zipkin
spec:
  type: LoadBalancer
  selector:
    app: zipkin
  ports:
  - name: ui
    port: 80
    targetPort: ui-port


zipkin-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: zipkin
spec:
  selector:
    matchLabels:
      app: zipkin
  template:
    metadata:
      labels:
        app: zipkin
    spec:
      containers:
      - name: zipkin
        image: openzipkin/zipkin:2.12
        imagePullPolicy: Always
        env:
        - name: STORAGE_TYPE
          value: mysql
        - name: SELF_TRACING_ENABLED
          value: "true"
        - name: MYSQL_HOST
          value: mysql-service
        - name: MYSQL_TCP_PORT
          value: "3306"
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              key: MYSQL_USER
              name: zipkin-props
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              key: MYSQL_PASSWORD
              name: zipkin-props
        - name: MYSQL_DATABASE
          valueFrom:
            secretKeyRef:
              key: MYSQL_DATABASE
              name: zipkin-props
        ports:
        - name: ui-port
          containerPort: 9411

zipkin-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: zipkin
spec:
  type: LoadBalancer
  selector:
    app: zipkin
  ports:
  - name: ui
    port: 80
    targetPort: ui-port

secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name:  zipkin-props
data:
  MYSQL_PASSWORD:  BASE64_ENCODED_PASSWORD
stringData:
  MYSQL_DATABASE: zipkin
  MYSQL_USER: root
type: Opaque

我认为,我需要更改邮政编码中的Charset。但是,除了自己创建另一个图像外,我别无选择。

1 个答案:

答案 0 :(得分:0)

我经常看到这个问题。根据我的经验,最常见的原因是在命令行上使用echo '$mypw' | base64对base64字符串进行了编码,这将在编码后的字符串中创建换行符。您需要使用-n开关来回显:echo -n '$mypw' | base64