Mysql必知必会
2020-07-08 18:30:35 19 举报
AI智能生成
Mysql必知必会整理
作者其他创作
大纲/内容
4.检索数据
<b>检索单列</b><br>select name from user;
<b>检索多列</b><br> select name,age from user;<br>
<b>检索所有列</b><br>select * from user;
<b>检索不同的行</b><br>select distinct age from user;
<b>限制结果</b><br>select age from user limit 2;<br>select age from user limit 2,2;
<b>完全限定的表明列名</b><br>select user.age from mybatis_test1.user;
5.排序检索数据
<b>排序数据</b><br>select name,age from order by name;
<b>按多个列排序</b><br>select name,age from user order by age,name;
cmd截图
<b>指定排序方向</b><br>select age ,name from user order by age desc,name;
<b>排序和limit找出最大大小值</b><br><b>select age from user order by age desc limit 1;</b>
7.数据过滤
<b>AND操作符</b><br>select * from user where age=11 and name='小二';
<b>OR操作符<br>select * from user where age=11 OR name='小二';</b><br>
<b>计算次序</b><br>AND优先级更高,和OR组合使用时,注意()的使用<br> select * from user where name='gg' or name='小二' and age=11;<br> select * from user where (name='gg' or name='小二') and age=11;<br>
<b>IN操作符</b><br> select * from where age in (11,77);<br>
<br>
<b>NOT 操作符</b><br>select * from user where age not in (11,77);
9.用正则表达式搜索
<b>基本字符匹配</b><br>select * from user where name regexp '1000';<br>select * from user where name regexp '.1000';<br>
<b>进行OR匹配</b><br> select * from user where name regexp '1000|2000';<br>
<b>匹配几个字符之一<br></b> select * from user where name regexp '[123]';<br>
<b>匹配范围</b><br> select * from user where name regexp '[1-5] tom';<br>
<b>匹配特殊字符</b><br><br>
匹配字符类
匹配多个实例
定位符
11.使用数据处理函数
<b>文本处理函数</b><br> select upper(name) ,age form user;<br>
日期处理函数<br>
数值处理函数
13.分组数据
数据分组:Group by
过滤分组:Having
分组和排序
15.联结表、16高级联结
联结
笛卡尔积
where子句的重要性
内部联结(等值联结)equijoin
使用表别名
使用不同类型的联结
自联结
自然联结
外部联结
使用带聚集函数的联结
18.全文本搜索
20.更新和删除数据
更新多列
Update Ignore
删除行数据
清空表数据truncate
22.使用视图
视图性能问题
视图的规则和限制
视图增删改
24.使用游标
Mysql游标只能用户存储过程和函数
游标的创建关闭
26.管理实务处理
start transaction/rollback/commit
使用保留点
自动提交设置
28.安全管理
管理用户
创建用户账号
修改用户名
删除用户
设置访问权限
查看访问权限
重置密码
权限列表
添加权限
移除权限
30.改善性能
索引
create index user_name on user(name);<br>show index from user;<br>drop index user_name on user;<br>
3.使用MySQL
<b>连接数据库:</b><br>mysql -u root -p 回车输入密码<br>
<b>连接异常解决</b>
<b>查看可连接数据库</b><br>show databases;
<b>选择数据库:</b><br>connect user; 或者 use user;<br>
<b>查看数据库下所有表</b><br>show tables;
查看表列信息<br><b>show columns from user;<br></b>或者<br><b>describe user;</b><br>
cmd截图
其他:<br>1.显示服务器状态:show status;<br>2.显示授予用户的安全权限:show grants;<br>3.显示服务器错误或者警告消息:show errors; show warnings;<br>4.显示创建指定数据库语句:show database mytest;<br>5.显示创建指定表:show table user;
cmd截图
6.过滤数据
<b>使用where子句</b><br>select age,name from user where age=77;
where子句操作符
<br>
<b>检查单个值</b><br>select age,name from user where name='GG';
<b>不匹配检查</b><br>select age,name from user where age <>11;
<b>范围值检查</b><br>select age,name from user where age between 50 and 100;
<b>空值检查</b><br>select age,name from user where start_date is null;
PS:<br><b>1.SQL语句不区分大小写,SELECT和select效果一样</b>
8.用通配符进行过滤
<b>LIKE操作符</b><br><br>
<b>百分号%操作符</b><br>select * from user where name like '小%';
<b>下划线通配符:_</b>
10.创建计算字段
<b>拼接字段</b><br> select concat(Trim(name),'(',Trim(age),')')as info from user;<br>
<b>执行算数计算</b><br><br>
12.汇总数据
聚集函数
14.使用子查询
利用子查询进行过滤
作为计算字段使用子查询
17.组合查询
UNION(自动取消重复行)
UNION ALL(允许重复行)
19.插入数据
插入完整的行
插入多个行
插入检索出的数据
21.创建、操纵表
创建表
多列主键
auto_increment查询
更新表
加字段
删除表
重命名表
23.使用存储过程
执行存储过程
创建存储过程
删除存储过程
25.使用触发器
创建触发器
删除触发器
使用触发器
27.全球化和本地化
29.数据库维护
检查表建
mysql数据类型
串数据类型
数值数据类型
日期和时间
二进制
0 条评论
下一页