convert_tz는 null을 반환합니다.
이게 어리석은 소리라는 건 알지만
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta') AS time
NULL을 출력합니다. Ubuntu 12.04 64 비트에서 MySQL Workbench를 사용하고 있으며 다른 랩톱 / OS에서 작동합니다 (MySQL Workbench도 사용).
이것은 시간대 테이블을 mysql에로드하지 않은 경우에 발생합니다.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
나는 허용 된 답변 (MySQL의 개발 사이트에서 동일)에서 명령을 실행 한 후 명령이 다음과 같은 시간대 사이에서 변환 할 수없는 이유를 알아 내려고 시간을 보낸 후이 스레드를 발견했습니다.
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','MET') AS time
: 그것은 OS X에 두 개의 파일이 원인 문제가 있다는 것을 밝혀 /usr/share/zoneinfo/Factory하고 /usr/share/zoneinfo/+VERSION.
수정 사항 ...이 파일을 /usr/share/zoneinfo/.bak/명령 을 허용 하는 것과 같은 다른 위치로 일시적으로 이동
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
예상되는 모든 시간대 정보를 완전히 채 웁니다.
이것은 설치된 MySQL 버전의 버그 일 수도 있고 아닐 수도 있습니다.
$ mysql --version
mysql Ver 14.14 Distrib 5.6.11, for osx10.6 (x86_64) using EditLine wrapper
나는 또한 STRICT_MODE.
어쨌든, 나는 이것이 수정을 찾는 사람에게 몇 가지 두통을 덜어주기를 바랍니다.
Windows 환경과는 별도로 다음과 같이 시간대를 설정할 수 있습니다.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
에서 윈도우 환경,
1. download Time zone description tables from http://dev.mysql.com/downloads/timezones.html
2. Stop MySQL server
3. Put then inside Mysql installation package (예 : C : \ Program Files \ MySQL \ data \ mysql)`
4. Start MySQL server
.. 작업이 끝났습니다 ..
당신이 점점 계속하는 경우 NULL에 대한 CONVERT_TZ다운로드 MySQL 데이터베이스에이 데이터베이스 테이블과 삽입을 http://www.4shared.com/folder/Toba2qu-/Mysql_timezone.html
이제 문제가 해결됩니다 .. :)
Windows에서 MySql을 사용하는 경우 시간대 데이터를 mysql 스키마에로드해야합니다. 다음은 좋은 HOWTO입니다. http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html
이렇게하지 않으면 CONVERT_TZ 함수가 입력 시간대 (예 : 'UTC', 'Asia / Jakarta')를 인식하지 못하고 단순히 NULL을 반환합니다.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
오류가 발생하면 https://bugs.mysql.com/bug.php?id=68861data too long for column 'abbreviation' at row 1 을 참조하십시오.
수정 사항은 다음을 실행하는 것입니다.
이것은 mysql 모드를 비활성화하는 줄을 추가하고 mysql이 잘린 데이터를 삽입하도록 허용합니다. 이것은 mysql이 끝에 null 문자를 추가하는 mysql 버그 때문입니다 (위 링크 참조).
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
(if the above gives error "data too long for column 'abbreviation' at row 1")
mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/zut.sql
echo "SET SESSION SQL_MODE = '';" > /tmp/mysql_tzinfo_to.sql
cat /tmp/zut.sql >> /tmp/mysql_tzinfo_to.sql
mysql --defaults-file=/etc/mysql/my.cnf --user=verifiedscratch -p mysql < /tmp/mysql_tzinfo_to.sql
1) Windows에는 C:\Program Files\MySQL\다른 답변과 마찬가지로 데이터 폴더가 없습니다 .
2)이 경우 C:\ProgramData\MySQL\MySQL Server 5.x\Data\mysql. 일반적으로이 폴더는 숨겨져 있으며 C:\ProgramData\때때로 보이지 않을 것 입니다.
3) Change the Settings in View tab to see Hidden files and Folders as explained here https://irch.info/index.php?pg=kb.page&id=133
4) Stop the MySQL service by searching for "services" in Windows Start button.
5) Then unzip the timezone_2017c_posix.zip and then copy the files in it (copy the files directly, don't copy the whole folder itself), and paste in C:\ProgramData\MySQL\MySQLServer5.x\Data\mysql\
6) For MySQL 5.7, timezone_2017c_posix.zip will just give a .sql file after unzipping and it may not solve the issue. So go ahead and download the zip file for 5.6 even if you are running MySQL 5.7 and copy those files to C:\ProgramData\MySQL\MySQL Server 5.x\Data\mysql\
7) Restart the MySQL server. To check if the CONVERT_TZ () is working, run this sql query.
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta'); and check for non-null output.
These are the steps to make it work if you're in windows and using MySQL 5.7.
- Right click on My Computer/Computer/This PC or whatever the name in your OS and choose Properties.
- Choose "Advanced system settings" from the left panel.
- Choose "Environmental Variables", enter the complete path name of your MySQL bin directory (generally it will be in, C:\Program Files\MySQL\MySQL Server 5.7\bin).
- Open cmd prompt, enter into mysql using
mysql -u root -p password. - Enter
use mysqlto select the MySQL DB. - Download the file "timezone_YYYYc_posix_sql.zip" (In the place of YYYY, substitute the maximum year available in that page like 2017 or 2018) from https://dev.mysql.com/downloads/timezones.html.
- Extract it and open the file in text editor.
- Copy the contents and execute in the cmd prompt.
On successful completion, you should be able to use CONVERT_TZ and other timezone functions.
MAMP PRO
- Open
Terminal cd /usr/share/zoneinfo/sudo mv +VERSION ~/Desktopcd /applications/MAMP/Library/binsudo ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysqlsudo mv ~/Desktop/+VERSION /usr/share/zoneinfo/
참고URL : https://stackoverflow.com/questions/14454304/convert-tz-returns-null
'Programing' 카테고리의 다른 글
| 고 루틴 중지 방법 (0) | 2020.09.21 |
|---|---|
| Gradle에서 현재 OS를 감지하는 방법 (0) | 2020.09.21 |
| 새 Mac OS X 터미널 창에서 명령 실행 (0) | 2020.09.21 |
| JavaScript를 사용하여 URL 유효성 검사 시도 (0) | 2020.09.21 |
| 업데이트 후 후크를 사용하여 다른 저장소에서 'git pull'을 실행할 때 "치명적 : git 저장소가 아님 : '.'"발생 (0) | 2020.09.21 |