mysql date() 详解

 

MySQL Date函数 1、获取当前时间

 
 
  1. MySQL> select current_timestamp();  
  2. +---------------------+  
  3. | current_timestamp() |  
  4. +---------------------+  
  5. | 2010-01-18 21:24:37 |  
  6. +---------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select current_date();  
  9. +----------------+  
  10. | current_date() |  
  11. +----------------+  
  12. | 2010-01-18 |  
  13. +----------------+  
  14. 1 row in set (0.00 sec)  
  15. MySQL> select current_time();  
  16. +----------------+  
  17. | current_time() |  
  18. +----------------+  
  19. | 21:24:46 |  
  20. +----------------+  
  21. 1 row in set (0.00 sec)  

MySQL Date函数 2、Unix时间

 
 
  1. MySQL> select unix_timestamp();  
  2. +------------------+  
  3. | unix_timestamp() |  
  4. +------------------+  
  5. | 1263821184 |  
  6. +------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select from_unixtime(1263821182);  
  9. +---------------------------+  
  10. | from_unixtime(1263821182) |  
  11. +---------------------------+  
  12. | 2010-01-18 21:26:22 |  
  13. +---------------------------+  
  14. 1 row in set (0.00 sec)  

MySQL Date函数 3、时间前后

 
 
  1. MySQL> select date_add(current_timestamp, interval 1 day);  
  2. +---------------------------------------------+  
  3. | date_add(current_timestamp, interval 1 day) |  
  4. +---------------------------------------------+  
  5. | 2010-01-19 21:27:53 |  
  6. +---------------------------------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select date_add(current_time, interval 1 day);  
  9. +----------------------------------------+  
  10. | date_add(current_time, interval 1 day) |  
  11. +----------------------------------------+  
  12. | NULL |  
  13. +----------------------------------------+  
  14. 1 row in set, 1 warning (0.00 sec)  
  15. MySQL> select date_add(current_date, interval 1 day);  
  16. +----------------------------------------+  
  17. | date_add(current_date, interval 1 day) |  
  18. +----------------------------------------+  
  19. | 2010-01-19 |  
  20. +----------------------------------------+  
  21. 1 row in set (0.00 sec)  
  22. MySQL> select date_sub(current_timestamp, interval 1 day);  
  23. +---------------------------------------------+  
  24. | date_sub(current_timestamp, interval 1 day) |  
  25. +---------------------------------------------+  
  26. | 2010-01-17 21:28:41 |  
  27. +---------------------------------------------+  
  28. 1 row in set (0.00 sec)  
  29. MySQL> select date_sub(current_date, interval 1 day);  
  30. +----------------------------------------+  
  31. | date_sub(current_date, interval 1 day) |  
  32. +----------------------------------------+  
  33. | 2010-01-17 |  
  34. +----------------------------------------+  
  35. 1 row in set (0.00 sec)  
  36. MySQL> select date_sub(current_time, interval 1 day);  
  37. +----------------------------------------+  
  38. | date_sub(current_time, interval 1 day) |  
  39. +----------------------------------------+  
  40. | NULL |  
  41. +----------------------------------------+  
  42. 1 row in set, 1 warning (0.00 sec)  

 

MySQL Date函数 4、时间间隔

 
 
  1. MySQL> select datediff('2010-01-18','2010-01-17');  
  2. +-------------------------------------+  
  3. | datediff('2010-01-18','2010-01-17') |  
  4. +-------------------------------------+  
  5. | 1 |  
  6. +-------------------------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select timediff('2010-01-18 12:00','2010-01-17 11:00');  
  9. +-------------------------------------------------+  
  10. | timediff('2010-01-18 12:00','2010-01-17 11:00') |  
  11. +-------------------------------------------------+  
  12. | 25:00:00 |  
  13. +-------------------------------------------------+  
  14. 1 row in set (0.00 sec)  

MySQL Date函数 5、时间转换

 
 
  1. MySQL> select time_to_sec('25:00:00');  
  2. +-------------------------+  
  3. | time_to_sec('25:00:00') |  
  4. +-------------------------+  
  5. | 90000 |  
  6. +-------------------------+  
  7. 1 row in set (0.00 sec)  
  8. MySQL> select sec_to_time(90000);  
  9. +--------------------+  
  10. | sec_to_time(90000) |  
  11. +--------------------+  
  12. | 25:00:00 |  
  13. +--------------------+  
  14. 1 row in set (0.00 sec)   
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL的binlog是二进制日志文件,用于记录数据库的修改操作。通过binlog可以实现数据的备份和恢复。根据引用\[1\]中的信息,可以使用show variables命令查看binlog相关的变量。其中,log_bin表示是否开启binlog,log_bin_basename表示binlog文件的基本名称,log_bin_index表示binlog索引文件的路径。 根据引用\[2\]中的信息,如果需要从上次备份到发现表被删除的时间点进行恢复,需要按照binlog序号从小到大的顺序进行恢复。可以使用mysqlbinlog命令来解析binlog文件并生成恢复脚本。根据引用\[2\]中的示例,可以使用mysqlbinlog命令按照序号逐个解析binlog文件,并将解析结果追加到恢复脚本中。 引用\[3\]中提到了mysqlbinlog的使用技巧。可以使用--stop-datetime参数指定停止解析binlog的时间点,或者使用--stop-date参数指定停止解析binlog的日期。通过这些参数的灵活组合,可以方便地选择需要恢复的binlog文件。 综上所述,MySQL的binlog是用于记录数据库修改操作的二进制日志文件。可以使用mysqlbinlog命令解析binlog文件并生成恢复脚本,按照binlog序号从小到大的顺序进行恢复。同时,可以使用mysqlbinlog的一些技巧来方便地选择需要恢复的binlog文件。 #### 引用[.reference_title] - *1* *2* *3* [mysql binlog 日志详解](https://blog.csdn.net/zll4859291/article/details/129670719)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值