Summary of the methods of setting time Zone and default Encoding in MySQL
Today, what the editor shares with you is a summary of the methods of setting the time zone and default coding of MySQL. Many people don't know much about it. Today, in order to let you know more about the method of setting the time zone and default coding of MySQL, I summarized the following for you. Let's read on. I'm sure you'll get something.
Situation description
When learning spring boot, install MySQL5.7 locally in Windows, configure the project, prompt you to set the time zone after startup, and find garbled codes in the process of use, which cannot be displayed in Chinese. The main reason for the above problems is that the time zone and code are not set in MySQL5.7.
Solution
1. Set the data source url of MySQL in the configuration file application.properties of spring boot
Spring.datasource.url=jdbc:mysql://localhost:3306/yunzhi_spring_boot?characterEncoding=utf-8&serverTimezone=GMT%2B8
Explanation:
CharacterEncoding is used to set the database code, using utf-8
ServerTimezone is the time zone set. "GMT%2B8" means GMT+8. Beijing time in East eighth Zone.
If you are interested, you can learn the difference between GMT and UTC.
2. If you feel troublesome to set this every time, modify the configuration file my.ini of MySQL directly and set two parameters:
Default-time-zone=+08:00character-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 a brief introduction to the method of setting the time zone and default coding of MySQL. Of course, the differences in the detailed use of the above still have to be understood by everyone. If you want to know more, welcome to follow the industry information channel!