mysql命令

1 连接

mysql -h host -u user -p password

2 创建和删除数据库

create database test;

drop database test;

3 创建和删除表

create table xxx();

drop table xxx;

4 mysql 默认不区分大小写

mysql的查询语句默认是不区分大小写的。

SELECT * FROM `city` where `name` = "WO";  这个查询语句会查询所有name = "WO","Wo","wO","wo"的记录。

若想要区分大小写,则需要使用binary关键字

SELECT * FROM `city` where `name` = BINARY("WO");  这条语句将只查询 name = "WO"的记录。

5 select / where / group by / having / order by的执行顺序

select->where->group by->having->order by

6 update 替换某个字段中的某个字符

update xxx set xx= replace(xxx, fromStr, toStr) where clause;

7 mysql中NULL值需要特殊处理

在mysql中,NULL值与任何其它值的比较都是false。mysql中处理NULL需要使用 is null 和 is not null。

8 模糊查询+正则查询

like字句

select * from test where uu like '%aaa%';  查找uu字段中含有aaa的的记录。

select * from test where uu like '%aaa'; 查找uu字段中以aaa结尾的数据记录。

select * from test where uu like 'aaa%'; 查找uu字段中以aaa开头的数据记录。

select * from test where uu like '_o_'; 查找uu字段中第二个字符是o的数据记录。

regexp

select * from test where uu regexp '^[aeiou]|haha$'; 查找uu字段中以元音字符开头或者以haha结尾的记录。

9 mysql查询结果展示

一般展示:

G 按行垂直展示:

原文地址:https://www.cnblogs.com/mydesky2012/p/11448925.html