The method of setting character set by mysql under Docker
The official image mysql:8 of Mysql. You can start the container with the following command:
Docker run-- name mysql002-p 3306 MYSQL_ROOT_PASSWORD=888888-idt mysql:8
If you use Springboot's JPA starter to access this database, the springboot application will throw the following exception because the database does not have a character set:
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 line: Unknown initial character set index '255' received from server
Because you failed to get server charset because you did not set the character set, you can use the following startup command to create the container and set the character set parameters:
Docker run-- name mysql005-p 3306 MYSQL_ROOT_PASSWORD=888888-idt mysql:8-- character-set-server=utf8mb4-- collation-server=utf8mb4_unicode_ci
Compared with the previous command to create the container, there are two more parameters-character-set-server=utf8mb4-collation-server=utf8mb4_unicode_ci, so that the mysql container sets the character set. Start the springboot application to operate the database again, and everything is fine.
Summary
The above is the method of setting the character set of mysql under Docker introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support to the website!