mysql 中 时间和日期函数
基础部分
一、MySQL 获得当前日期时间 函数
1.1 获得当前日期+时间(date + time)函数:now()
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数:
current_timestamp()
,current_timestamp
,localtime()
,localtime
,localtimestamp -- (v4.0.6)
,localtimestamp() -- (v4.0.6)
这些日期时间函数,都等同于 now()。鉴于 now() 函数简短易记,建议总是使用 now() 来替代上面列出的函数。
1.2 获得当前日期+时间(date + time)函数:sysdate()
sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。看下面的例子就明白了:
mysql> select now(), sleep(3), now();
+---------------------+----------+---------------------+
| now() | sleep(3) | now() |
+---------------------+----------+---------------------+
| 2008-08-08 22:28:21 | 0 | 2008-08-08 22:28:21 |
+---------------------+----------+---------------------+
mysql> select sysdate(), sleep(3), sysdate();
+---------------------+----------+---------------------+
| sysdate() | sleep(3) | sysdate() |
+---------------------+----------+---------------------+
| 2008-08-08 22:28:41&nbs
相关文档:
在生产应用中,某台“Nginx+PHP+MySQL”接口数据服务器,扮演的角色十分重要,如果服务器硬件或Nginx、MySQL发生故障,而 短时间内无法恢复,后果将非常严重。为了避免单点故障,我设计了此套方案,编写了failover.sh脚本,实现了双机互备、全自动切换,故障转移时间 只需几十秒。
一、双机互备、全自动切换方案 ......
高性能MySql学习笔记
1.针对应用建立自己的索引
URL查找例子
select * from tUrl where url='http://www.163.com';
以url(字符串)作行为索引会使得作为索引结构的B-Tree变大,可以移除url列上的索引,并添加一个url_crc索引列,
先建立表:
create tables tUrl(
......
数据库表单的创建
mysql> create database shuishengmu;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql & ......
mysql
> SHOW VARIABLES LIKE
'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection |
latin1 |
| character_set ......
今天在写实习生的培训PPT时,用mysql的command line client插入一条带中文的记录时,报data to long的错误,
在网上查看了相关资料,说的是因为这个console使用了一种编码方式,把命令编码后再发送到数据库,具体请参看http://www.cnblogs.com/ovliverlin/archive/2007/11/26/972549.html,说的比较详细,本人看完后,直接 ......