如何修改MySQL中的system_time_zone?已设置global.time_zone为+05:30但system_time_zone仍显示UTC
Hey there! Let's clear up the confusion first: @@system_time_zone isn't a setting you can tweak directly via MySQL commands—it's pulled straight from your operating system's timezone. That's why your @@global.time_zone is correctly set to +05:30, but @@system_time_zone still shows UTC.
Here's how to fix it:
Step 1: Set Your Operating System's Timezone to IST
MySQL reads the system timezone only when it starts up, so you need to update your OS timezone first.
For Linux Systems:
- Check your current timezone status:
timedatectl status - Set the timezone to Indian Standard Time (IST maps to
Asia/Kolkata):sudo timedatectl set-timezone Asia/Kolkata
For Windows Systems:
- Open Control Panel > Date and Time > Change time zone
- Select (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi from the dropdown and save your changes.
Step 2: Restart MySQL Service
Since MySQL only fetches the system timezone on startup, you'll need to restart the service to apply the new setting:
Linux:
sudo systemctl restart mysql
Windows:
- Press
Win + R, typeservices.mscand hit Enter to open the Services manager - Locate the MySQL service, right-click it, and select Restart
Step 3: Verify the Change
Log back into MySQL and run the query again:
SELECT @@system_time_zone;
You should now see either IST or Asia/Kolkata (depending on your MySQL version)—both correspond to the +05:30 offset you want.
A Quick Side Note:
If you don't want to modify your OS timezone, rest easy: as long as @@global.time_zone is set to +05:30, MySQL will handle all date/time operations correctly using that timezone. @@system_time_zone is just a reflection of your OS's timezone and doesn't impact MySQL's internal time handling.
内容的提问来源于stack exchange,提问作者rk_py

