Nacos: mysql8.0 support error

Created on 10 Nov 2019  ·  14Comments  ·  Source: alibaba/nacos

Issue Description

Type: bug report

Describe what happened (or what feature you want)

mode: standalone
db: mysql8.0
start.out

Describe what you expected to happen

run ok

How to reproduce it (as minimally and precisely as possible)

version: "3"
services:
  nacos:
    image: nacos/nacos-server:1.1.4
    container_name: nacos-standalone-mysql
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
      - MYSQL_DATABASE_NUM=1
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_MASTER_SERVICE_HOST=mysql
      - MYSQL_MASTER_SERVICE_DB_NAME=nacos
      - MYSQL_MASTER_SERVICE_PORT=3306
      - MYSQL_SLAVE_SERVICE_HOST=
      - MYSQL_SLAVE_SERVICE_PORT=
      - MYSQL_MASTER_SERVICE_USER=root
      - MYSQL_MASTER_SERVICE_PASSWORD=qwer1234
    volumes:
      - ./standalone-logs/:/home/nacos/logs
      - ./custom.properties:/home/nacos/init.d/custom.properties
    ports:
      - "8848:8848"
      - "9555:9555"
    restart: on-failure

i add mysql-connector-java-8.0.18.jar to /home/nacos/plugins/mysql-connector-java-8.0.18.jar

Tell us your environment

centos 8
docker-ce 19
mysql 8.0

Anything else we need to know?

i try to change application.properties 's mysql string
db.url.0=jdbc:mysql://${MYSQL_MASTER_SERVICE_HOST}:${MYSQL_MASTER_SERVICE_PORT:3306}/${MYSQL_MASTER_SERVICE_DB_NAME}?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
but no ok

Most helpful comment

2057

All 14 comments

What's the result of non-docker?

non-docker

  • add mysql-connector-java-8.0.18.jar to plugins/mysql/mysql-connector-java-8.0.18.jar
  • add config to conf/application.properties
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
db.user=root
db.password=qwer1234
  • mysql8.0 config is default, nacos is utf8
  • the last caused
Caused by: java.lang.NullPointerException
    at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2983)
    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1873)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1802)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1206)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234)
    at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2085)
    ... 28 more

new driver don't load ?

Try the solution commented in https://github.com/alibaba/nacos/pull/855

i see #855 first
i forget look the java's version
java8 is ok
java11 is wrong

java11下
classpath路径也指对了
但是就是加载不了新驱动
把pom升级自己编译倒是没问题

java8下会加载新驱动,并且提示旧驱动废弃

java11下
classpath路径也指对了
但是就是加载不了新驱动
把pom升级自己编译倒是没问题

java8下会加载新驱动,并且提示旧驱动废弃

参考下:
https://github.com/alibaba/nacos/blob/3a4de81981c54f926cd17a02c5cecd3b8dc0e8ed/distribution/bin/startup.sh#L100

有可能是java版本判断错误,还以为是java8,导致加载的方式不对。

java11下
classpath路径也指对了
但是就是加载不了新驱动
把pom升级自己编译倒是没问题
java8下会加载新驱动,并且提示旧驱动废弃

参考下:

https://github.com/alibaba/nacos/blob/3a4de81981c54f926cd17a02c5cecd3b8dc0e8ed/distribution/bin/startup.sh#L100

有可能是java版本判断错误,还以为是java8,导致加载的方式不对。

判断没错的,脚本执行的时候输出了最终语句,java11带ext是启动不起来的。

/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java  -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -cp .:/Users/zhfish/docker/nacos/nacos/plugins/mysql -Xlog:gc*:file=/Users/zhfish/docker/nacos/nacos/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400 -Dnacos.home=/Users/zhfish/docker/nacos/nacos -Dloader.path=/Users/zhfish/docker/nacos/nacos/plugins/health -jar /Users/zhfish/docker/nacos/nacos/target/nacos-server.jar  --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/Users/zhfish/docker/nacos/nacos/conf/ --logging.config=/Users/zhfish/docker/nacos/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288

loader.path

你参考这个,放到loader.path下试试:
https://stackoverflow.com/questions/36921842/springboot-loader-path-unable-to-load-external-jar

赞,这个行了
启动脚本改成这样

JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
  JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins/health,${BASE_DIR}/plugins/mysql,${BASE_DIR}/plugins/cmdb"
  JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400"
else
  JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins/health"
  JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${BASE_DIR}/plugins/cmdb:${BASE_DIR}/plugins/mysql"
  JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
fi

JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/${SERVER}.jar"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} --spring.config.location=${CUSTOM_SEARCH_LOCATIONS}"
JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/nacos-logback.xml"
JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288"

好的,稍后我再确认下是否loader.path对于java8一样有效。

我这边,统一用loader.path, java8和11都能加载新驱动

我这边,统一用loader.path, java8和11都能加载新驱动

能否提一个PR共享一下?

可以,没问题,一会得空就提一下
只是脚本的小改动,没好意思提PR

2057

Was this page helpful?
0 / 5 - 0 ratings