mysql常用操作

时间戳转换

datetime转换为时间戳:UNIX_TIMESTAMP()

时间戳转换为datetime:FROM_UNIXTIME()

mysql> create table testtime(id int auto_increment not null,timestr int,PRIMARY KEY(id));

Query OK, 0 rows affected (0.01 sec)



mysql> desc testtime;

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

| Field   | Type    | Null | Key | Default | Extra          |

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

| id      | int(11) | NO   | PRI | NULL    | auto_increment |

| timestr | int(11) | YES  |     | NULL    |                |

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

2 rows in set (0.01 sec)



mysql> insert into testtime(timestr) values(UNIX_TIMESTAMP('2014-06-01 21:00:00'));

Query OK, 1 row affected (0.00 sec)



mysql> select FROM_UNIXTIME(timestr) from testtime;

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

| FROM_UNIXTIME(timestr) |

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

| 2014-06-01 21:00:00    |

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

1 row in set (0.00 sec)



mysql> 

 

大小写转换

小写转换为大写:UPPER()

大写转换为小些:LOWER()

mysql> select LOWER(title) from film limit 4\G

*************************** 1. row ***************************

LOWER(title): academy dinosaur

*************************** 2. row ***************************

LOWER(title): ace goldfinger

*************************** 3. row ***************************

LOWER(title): adaptation holes

*************************** 4. row ***************************

LOWER(title): affair prejudice

4 rows in set (0.00 sec)

 

求平均值:AVG

COUNT

SUM

MAX

MIN

ROUND(coul,2)  四舍五入,且保留两位小数

 

show create table '表名';

可以显示创建表的sql语句,包括主键,索引,字符集等信息

show columns from '表名'

和desc '表名'效果一样

explain sql语句

在sql语句前面加上explain,可以查看执行计划

 

show table status from '数据库名' where name='表名'

查看数据表存储引擎类型

你可能感兴趣的:(mysql)