MySQL和Oracle时区设置比较
MYSQL:注意时区会影响TIMESTAMP的取值,默认为系统时区为TIME_ZONE=SYSTEM, 动态可以修改set global time_zone =
MYSQL:
注意时区会影响TIMESTAMP的取值,默认为系统时区为TIME_ZONE=SYSTEM,
动态可以修改
set global time_zone = '+8:00';
然后
my.cnf加上,永久修改
default-time_zone = '+8:00'
The current time zone. This variable is used to initialize the time zone for each client that
connects. By default, the initial value of this is 'SYSTEM'(which means, “use the value of
system_time_zone”).
也就是说每个链接都会使用这个参数作为他的默认时区,而TIMESTMAP是根据客户端的时区不同而不同,所以如果如果这个参数设置有误会导致TIMESTAMP时间出现问题
MYSQL的测试:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2015-06-12 12:10:13 |
+---------------------+
1 row in set (0.00 sec)
mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2015-06-12 12:10:18 |
+---------------------+
1 row in set (0.00 sec)
mysql> select current_timestamp from dual;
+---------------------+
| current_timestamp |
+---------------------+
| 2015-06-12 12:10:46 |
+---------------------+
1 row in set (0.00 sec)
mysql> set time_zone='+00:00';
Query OK, 0 rows affected (0.00 sec)
mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2015-06-12 04:11:01 |
+---------------------+
1 row in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2015-06-12 04:11:04 |
+---------------------+
1 row in set (0.00 sec)
mysql> select current_timestamp from dual;
+---------------------+
| current_timestamp |
+---------------------+
| 2015-06-12 04:11:06 |
+---------------------+
1 row in set (0.01 sec)
可见MYSQL的NOW(),SYSDATE(),current_timestamp 均跟着客户端时区走的。
Oracle:
另外说一下ORACLE的时区问题,ORACLE时区分为
dbtimezone和sessiontimezone
其中DBTIMEZONE只和TIMESTAMP WITH LOCAL TIME ZONE有关,在TIMESTAMP WITH LOCAL TIME ZONE类型存入数据库中,实际上是转换为DBTIMEZONE的时间,取出的时候
自动加上客户端的SESSIONTIMEZONE的偏移量,文档如下:
TimeStamp with Local Time Zone (TSLTZ) data stores internally the time converted to/from the database timezone (see point 3) from the timezone specified at insert/select time.
Note that the data stored in the database is normalized to the database time zone, and the time zone offset is not stored as part of the column data, the current DBTIMZONE is used. When users retrieve the data, Oracle Database returns it in the users' local session time zone from the current DBTIMEZONE.
而其他的时间类型和DBTIMEZONE无关,这也是为什么有了TIMESTAMP WITCH LOCAL TIME ZONE修改DBTIMEZONE不行的原因,因为如果修改了DBTIMEZONE会导致时间错误。
实际上MYSQL的TIMESTAMP类型和ORACLE的TIMESTAMP WITCH LOCAL TIME ZONE类型都是根据客户端的时间来进行返回时间,但是MYSQL可以简单的设置
time_zone参数来改变所有连接的时区,这样返回的时间能够正确。
在说明一下ORACLE的TIMESTAMP和MYSQL的TIMESTAMP完全不同,
ORACLE的TIMESTAMP是为了精确到秒后6位,
而MYSQL的TIMESTAMP是为了更少的存储单元(DATETIME为4字节,TIMESTAMP为1个字节)但是范围为1970的某时的开始到2037年,而且会根据客户端的时区判断返回值
而sessiontimezone,则影响着客户端的时区,TIMESTAMP WITCH LOCAL TIME ZONE也会跟着这个时区进行改变,其他数据类型如DATE,TIMESTAMP等不会受到影响
可以再ALTER SESSION中设置也可以设置环境变量TZ=
如:
ALTER SESSION SET TIME_ZONE = '-05:00';
或者
export TZ='Asia/Shanghai';
做个简单的实验
SQL> desc testtim;
Name Null? Type
----------------------------------------- -------- ----------------------------
DATE1 TIMESTAMP(6)
DATE2 TIMESTAMP(6) WITH TIME ZONE
DATE3 TIMESTAMP(6) WITH LOCAL TIME ZONE
SQL> select * from testtim;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.
