Home > Database > Mysql Tutorial > body text

How to set time zone and default encoding in MySQL

藏色散人
Release: 2020-03-10 08:54:27
forward
7446 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template