# 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;