【Mysql】修改mysql時區
首先需要檢視mysql的當前時區,用time_zone引數
mysql> show global variables like '%zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST | ---系統時間,北京時間
| time_zone | SYSTEM | ----mysql所用的時區,這裡是呼叫系統時區,也就是北京時間
+------------------+--------+
2 rows in set (0.17 sec)
驗證下:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-11-30 17:11:55 |
+---------------------+
1 row in set (0.18 sec)
修改為utc時區
mysql> set time_zone='+0:00';
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-11-30 09:12:06 |
+---------------------+
1 row in set (0.18 sec)
修改為東八區
mysql> set time_zone='+8:00';
Query OK, 0 rows affected (0.24 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-11-30 17:21:40 |
+---------------------+
1 row in set (0.72 sec)
永久修改可以透過修改my.cnf
在 [mysqld] 之下加
default-time-zone=timezone
來修改時區。如:
default-time-zone = '+8:00'
修改完了記得記得重啟msyql
注意一定要在 [mysqld] 之下加 ,否則會出現 unknown variable 'default-time-zone=+8:00'
注意:時區這個對timestamp型別的才有影響,datetime 是沒影響的,如:
mysql> select * from uc_smallfeature_sharerecords(時間戳是timestamp型別);
+------+---------------------+-------------+----------+--------+----------+
| id | create_time | destination | platform | userid | username |
+------+---------------------+-------------+----------+--------+----------+
| 3425 | 2018-12-25 19:42:51 | 123213 | 123 | 123 | 123 |
+------+---------------------+-------------+----------+--------+----------+
mysql> select * from uc_push_token(時間戳是datetime型別);
+---------+-----------+-------+---------------------+---------------------+
| user_id | push_type | token | create_time | update_time |
+---------+-----------+-------+---------------------+---------------------+
| 1 | 0 | | 2018-12-25 19:40:49 | 2018-12-25 19:40:49 |
+---------+-----------+-------+---------------------+---------------------+
mysql> show global variables like '%zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | UTC |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
mysql> set global time_zone='+0:00';
Query OK, 0 rows affected (0.00 sec)
重連查詢:
mysql> select * from uc_smallfeature_sharerecords;(timestamp型別的變了)
+------+---------------------+-------------+----------+--------+----------+
| id | create_time | destination | platform | userid | username |
+------+---------------------+-------------+----------+--------+----------+
| 3425 | 2018-12-25 11:42:51 | 123213 | 123 | 123 | 123 |
+------+---------------------+-------------+----------+--------+----------+
1 row in set (0.00 sec)
mysql> select * from uc_push_token;(datetime型別的不會變)
+---------+-----------+-------+---------------------+---------------------+
| user_id | push_type | token | create_time | update_time |
+---------+-----------+-------+---------------------+---------------------+
| 1 | 0 | | 2018-12-25 19:40:49 | 2018-12-25 19:40:49 |
+---------+-----------+-------+---------------------+---------------------+
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2222318/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【MySQL】時區修改MySql
- 修改MySQL的時區MySql
- docker中的MySQL修改時區DockerMySql
- mac mysql修改預設時區為 utcMacMySql
- mysql時區與時間函式MySql函式
- MySQL中的時區設定MySql
- MySQL資料庫時區配置MySql資料庫
- 【Mysql】關於一個mysql的坑比時區問題MySql
- mysql的時區錯誤問題MySql
- mysql編碼修改MySql
- mysql表引擎修改MySql
- Oracle修改時區Oracle
- AIX 修改時區AI
- Esxi 修改時區
- MYSQL和ORACLE時區設定比較MySqlOracle
- mysql 忘記密碼,mysql修改密碼MySql密碼
- Mysql修改server uuidMySqlServerUI
- MySQL修改表的列名MySql
- mysql修改root密碼MySql密碼
- 修改mysql root密碼MySql密碼
- 修改MySQL字符集MySql
- mysql 字符集修改MySql
- MySQL修改字符集MySql
- mysql修改埠經驗MySql
- 【mysql】關於連線mysql資料庫時出現的時區錯誤time zoneMySql資料庫
- Mysql匯入大表檔案時注意修改引數MySql
- weblogic修改時區Web
- Ubuntu Server修改時區UbuntuServer
- MySQL模糊查詢(like)時區分大小寫MySql
- MySQL時區導致無法產生表MySql
- 修改Docker容器的時區為中國時區Docker
- mysql 時間MySql
- mysql8.0修改密碼MySql密碼
- 修改 MySQL 登入密碼MySql密碼
- 修改MySQL中的資料MySql
- mysql如何修改所有的definerMySql
- mysql修改管理員密碼MySql密碼
- MySQL 修改最大連線數MySql