目录
1、mysql时区问题
2、Ubuntu时区问题
解决docker中mysql时区问题_杨园亮的博客-CSDN博客
问题
数据库插入的时间统统相差8个小时。
//初步怀疑服务器时间不对。date看下时间是对的
//然后怀疑代码问题,检查代码后没有问题
//最后怀疑mysql的问题。
--docker exec -it mysql /bin/bash
--mysql -uroot -p
--show variables like '%time_zone%'
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | UTC |
| time_zone | SYSTEM |
+------------------+--------+
//可见使用的是系统时区
//改文件
-- docker cp mysql:/etc/mysql/my.cnf ./my.cnf
-- vim my.cnf 最后一行加上
default-time-zone = '+8:00'
-- docker cp ./my.cnf mysql:/etc/mysql/my.cnf
-- docker container mysql restart
vi 命令不可用
Docker教程:解决Docker容器内不能使用vim命令的问题 - .NET开发菜鸟 - 博客园
$ apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package vim
$ apt-get update
Get:1 http://repo.mysql.com/apt/debian buster InRelease [22.1 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://deb.debian.org/debian buster InRelease [122 kB]
Get:4 http://repo.mysql.com/apt/debian buster/mysql-8.0 amd64 Packages [8447 B]
Get:5 http://security.debian.org/debian-security buster/updates/main amd64 Packages [318 kB]
Get:6 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:7 http://deb.debian.org/debian buster/main amd64 Packages [7911 kB]
Get:8 http://deb.debian.org/debian buster-updates/main amd64 Packages [8796 B]
Fetched 8507 kB in 9min 30s (14.9 kB/s)
Reading package lists... Done
$ apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
vim-common vim-runtime xxd
Suggested packages:
ctags vim-doc vim-scripts
The following NEW packages will be installed:
vim vim-common vim-runtime xxd
0 upgraded, 4 newly installed, 0 to remove and 9 not upgraded.
Need to get 7392 kB of archives.
After this operation, 33.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
//完成安装
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | UTC |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2022-05-01 00:20:01 |
+---------------------+
1 row in set (0.00 sec)
mysql>
root@1cdf7c371321:/usr/bin# date -R
Wed, 11 May 2022 12:20:10 +0000
root@1cdf7c371321:/etc# apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [61.0 kB]
Get:5 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [84.2 kB]
Hit:6 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [79.7 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [98.8 kB]
Fetched 544 kB in 6s (84.7 kB/s)
Reading package lists... Done
//安装 tzdata命令
root@1cdf7c371321:/etc# apt-get install -y tzdata
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
tzdata
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 342 kB of archives.
After this operation, 3925 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 tzdata all 2022a-0ubuntu1 [342 kB]
Fetched 342 kB in 4s (86.3 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package tzdata.
(Reading database ... 23880 files and directories currently installed.)
Preparing to unpack .../tzdata_2022a-0ubuntu1_all.deb ...
Unpacking tzdata (2022a-0ubuntu1) ...
Setting up tzdata (2022a-0ubuntu1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.34.0 /usr/local/share/perl/5.34.0 /usr/lib/x86_64-linux-gnu/perl5/5.34 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.34 /usr/share/perl/5.34 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Configuring tzdata
------------------
Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting
a list of cities, representing the time zones in which they are located.
1. Africa 3. Antarctica 5. Arctic 7. Atlantic 9. Indian 11. US
2. America 4. Australia 6. Asia 8. Europe 10. Pacific 12. Etc
Geographic area: 6 //选序号6
Please select the city or region corresponding to your time zone.
1. Aden 14. Beirut 27. Gaza 40. Karachi 53. Muscat 66. Riyadh 79. Tokyo
2. Almaty 15. Bishkek 28. Harbin 41. Kashgar 54. Nicosia 67. Sakhalin 80. Tomsk
3. Amman 16. Brunei 29. Hebron 42. Kathmandu 55. Novokuznetsk 68. Samarkand 81. Ujung_Pandang
4. Anadyr 17. Chita 30. Ho_Chi_Minh 43. Khandyga 56. Novosibirsk 69. Seoul 82. Ulaanbaatar
5. Aqtau 18. Choibalsan 31. Hong_Kong 44. Kolkata 57. Omsk 70. Shanghai 83. Urumqi
6. Aqtobe 19. Chongqing 32. Hovd 45. Krasnoyarsk 58. Oral 71. Singapore 84. Ust-Nera
7. Ashgabat 20. Colombo 33. Irkutsk 46. Kuala_Lumpur 59. Phnom_Penh 72. Srednekolymsk 85. Vientiane
8. Atyrau 21. Damascus 34. Istanbul 47. Kuching 60. Pontianak 73. Taipei 86. Vladivostok
9. Baghdad 22. Dhaka 35. Jakarta 48. Kuwait 61. Pyongyang 74. Tashkent 87. Yakutsk
10. Bahrain 23. Dili 36. Jayapura 49. Macau 62. Qatar 75. Tbilisi 88. Yangon
11. Baku 24. Dubai 37. Jerusalem 50. Magadan 63. Qostanay 76. Tehran 89. Yekaterinburg
12. Bangkok 25. Dushanbe 38. Kabul 51. Makassar 64. Qyzylorda 77. Tel_Aviv 90. Yerevan
13. Barnaul 26. Famagusta 39. Kamchatka 52. Manila 65. Rangoon 78. Thimphu
Time zone: 70 //选序号70
Current default time zone: 'Asia/Shanghai'
Local time is now: Wed May 11 21:29:55 CST 2022.
Universal Time is now: Wed May 11 13:29:55 UTC 2022.
Run 'dpkg-reconfigure tzdata' if you wish to change it.
root@1cdf7c371321:/etc# date //再看时间,正常
Wed May 11 21:30:35 CST 2022
root@1cdf7c371321:/etc#