Re-introduced “Unknown initial character set index” error?

前端 未结 1 341
一整个雨季
一整个雨季 2021-01-06 11:00

I have a Java client application that connects to a mysql server. Both the client and the server are running in docker containers.

I noticed that the of

相关标签:
1条回答
  • 2021-01-06 11:33

    This talks about the changes that have happened since 8.0 One of the point that has been listed for you to refer is this:

    Character Set Support

    Important Change: The default character set has changed from latin1 to utf8mb4. These system variables are affected:

    The default value of the character_set_server and character_set_database system variables has changed from latin1 to utf8mb4.

    The default value of the collation_server and collation_database system variables has changed from latin1_swedish_ci to utf8mb4_0900_ai_ci.

    As a result, the default character set and collation for new objects differ from previously unless an explicit character set and collation are specified. This includes databases and objects within them, such as tables, views, and stored programs.


    One way to preserve the previous defaults is to start the server with these lines in my.cnf file:

    [mysqld]
    character_set_server=latin1
    collation_server=latin1_swedish_ci
    

    Another option, since you are running docker, is to specify these configuration options as command line arguments to the docker run command. For example:

    docker run -d \
    --network my-net \
    -h mysqldb \
    --name mysqldb \
    -p 3306:3306 \
    -e MYSQL_RANDOM_ROOT_PASSWORD=yes \
    -e MYSQL_DATABASE=mydb \
    -e MYSQL_USER=admin \
    -e "MYSQL_PASSWORD=admin" \
    mysql:8 --character-set-server=latin1 --collation-server=latin1_swedish_ci
    

    On the client, if you want to make changes - hopefully these should suffice:

    To use 4-byte UTF-8 character sets with Connector/J, configure the MySQL server with character_set_server=utf8mb4, and leave characterEncoding out of the Connector/J connection string.

    Connector/J will then auto-detect the UTF-8 setting

    Hope this helps!

    0 讨论(0)
提交回复
热议问题