mysql

# mysql 大小写不明感

 

1. 从文本中载入数据
要想将文本文件pet.txt 装载到pet表中 使用以下命令
mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

请注意如果用Windows 中的编辑器(使用/r/n 做为行的结束符) 创建文件,应使用:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet LINES TERMINATED BY '/r/n';

2 日期计算

mysql> select curdate(), year(curdate()) ,month(curdate()) , dayofmonth(curdate()), day(curdate());
+------------+-----------------+------------------+-----------------------+----------------+
| curdate()  | year(curdate()) | month(curdate()) | dayofmonth(curdate()) | day(curdate()) |
+------------+-----------------+------------------+-----------------------+----------------+
| 2011-03-01 |            2011 |                3 |                     1 |              1 |
+------------+-----------------+------------------+-----------------------+----------------+

 

mysql> select  now() , right(curdate(), 5) ,right(now(), 9) , left(curdate(), 4);
+---------------------+---------------------+-----------------+--------------------+
| now()               | right(curdate(), 5) | right(now(), 9) | left(curdate(), 4) |
+---------------------+---------------------+-----------------+--------------------+
| 2011-03-01 15:36:47 | 03-01               |  15:36:47       | 2011               |
+---------------------+---------------------+-----------------+--------------------+

 

mysql> select now(), Date_add(now(), interval 1 month);
+---------------------+-----------------------------------+
| now()               | Date_add(now(), interval 1 month) |
+---------------------+-----------------------------------+
| 2011-03-01 19:16:42 | 2011-04-01 19:16:42            |
+---------------------+-----------------------------------+

 

# mysql NULL 与 0 和 空字符串的比较

 

概念上,NULL 意味着“没有值”或“未知值”,

mysql> SELECT 1 = NULL, 1 <> NULL, 1 < NULL, 1 > NULL;

+----------+-----------+----------+----------+

| 1 = NULL | 1 <> NULL | 1 < NULL | 1 > NULL |

+----------+-----------+----------+----------+

|     NULL |      NULL |     NULL |     NULL |

+----------+-----------+----------+----------+
mysql>
SELECT 0 IS NULL, 0 IS NOT NULL, '' IS NULL, '' IS NOT NULL;

+-----------+---------------+------------+----------------+

| 0 IS NULL | 0 IS NOT NULL | '' IS NULL | '' IS NOT NULL |

+-----------+---------------+------------+----------------+

|         0 |             1 |          0 |              1 |

+-----------+---------------+------------+----------------+
# 正则查询 查看建筑名称以w 开头的数据
select * from tb_building where build_name regexp '^w';
# 修改自增长起始值
ALTER TABLE tbl AUTO_INCREMENT = 1;

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值