Situation description
When learning spring boot, you need to install MySQL5.7 locally on Windows. After configuring the project, after starting, it prompts that you need to set the time zone, and garbled characters are found during use. , Chinese cannot be displayed. The main reason for the above problems is that the time zone and encoding are not set in MySQL5.7.
Recommended: "mysql tutorial"
Solution
1. In the spring boot configuration file application.properties Set the data source url of MySQL
spring.datasource.url=jdbc:mysql://localhost:3306/yunzhi_spring_boot?characterEncoding=utf-8&serverTimezone=GMT%2B8
Explanation:
characterEncoding is to set the database encoding, using utf-8;
serverTimezone is to set the time zone, "GMT+8" is GMT 8, Dongba District Beijing time;
If you are interested, you can learn about the difference between GMT and UTC.
2. If you set it up like this every time, it feels very troublesome. Directly modify the MySQL configuration file my.ini and set two parameters:
default-time-zone=+08:00 character-set-server=utf8
Then save and restart the MySQL service.
The MySQL url in the project can be simplified to:
spring.datasource.url=jdbc:mysql://localhost:3306/yunzhi_spring_boot
The above is the detailed content of How to set time zone and default encoding in MySQL. For more information, please follow other related articles on the PHP Chinese website!