Docker mysql Docker mysql set character set method

  • 2020-09-16 07:54:29
  • OfStack

Mysql's official mirror, mysql:8, starts the container with the following command:


docker run --name mysql002 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=888888 -idt mysql:8

If you access the database using JPA starter of Springboot, since the database has no character set, the springboot application throws the following exception:


java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
  at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1794)
  at 
  ......
  ...
  .

The key message is this 1 line: Unknown initial character set index '255' received from server;

server charset failed to get server because no character set was set. You can use the following startup command to create the container and set character set parameters:


docker run --name mysql005 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=888888 -idt mysql:8 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

There are two more parameters than in the previous command to create the container �character-set-server=utf8mb4 �collation-server=utf8mb4_unicode_ci In this way, the mysql container set the character set, start springboot application operation database again, 1 cut normal;

conclusion


Related articles: