找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
增加条件语句进行查询:select * from 表单名 where 条件;
where 后面条件语句的and和or用法跟delete删除命令用法相同

update
修改表中指定字段的所有数据:
update 表单名 set 字段名 = 值;
修改表中指定字段的指定数据:
update 表单名 set 字段名 = 值 where 条件;        
修改表中多个字段的值:
update 表单名 set 字段名1 = 值1,字段名2=值2 where 条件;
<=小于等于
>=大于等于
!=不等于
查询区间的值:...<=...  and... >=...  、...between m and n
例子:select * from wuhan5 where time <='2021-06-10' and time>='2021-06-08';
           select * from wuhan5 where time between '        2021-06-8' and '2021-06-10';
null不是一个可以查询的值,要用特定的语法进行查询
is not null 查询不为null的值
is null 查询为null的值
例子:select * from wuhan5 where avg(要查询的字段名) is not null;
查询在这个集合当中的值:
select * from 表单名 where 字段名 in (值1,值2,值3);
例子:select * from wuhan5 where id in (3,5,8);
查询不在这个集合当中的数据:
select * from 表单名 where 字段名 not in(值1,值2,值3);
查询某个字段模糊匹配成功的数据:
select * from +表单名 where 字段名 like “%值%” ;
%用于匹配字段开头和结尾,可以只放一个%在值前面作为数据开头,或者后面作为结尾
查询限定的数量的数据,即查询从第m行开始的n行数据:
select * from +表名 where 字段 limit m,n
m 指下标,n指限定的数量,下标为m的开始的n条数据

查询的数据根据某个字段从小到大排序:
select * from +表名 order by 字段 asc;
order by ...asc 从小到大排序
查询的数据根据某个字段从大到小排序:
select * from +表名 order by 字段 desc;
order by ... desc 从大到小排序
查询的数据根据某个字段进行分组:
select 字段,count(*)  from +表名 group by 字段;
group by ... 根据字段分组
count(*) 统计的函数,统计查询数据的数量
例子:select phone,count(*)  from wuhan5 group by phone;
查询的数据根据某个字段进行分组再条件过滤:
select 字段,count(字段) as 赋值对象  from +表名 group by 字段 having 条件;
where不能接在聚合函数和分组后面使用,如果增加条件用having代替where
having跟在group by 后面,作用相当于where。
as 取别名
例子:select phone,count(phone) as t  from wuhan5 group by phone having t>=2;
查询表单有多少条数据,查询列表的长度:
select count(*) from 表名;
查询某个字段求和:
select sum(字段) from +表名;
查询某个字段进行平均值:
select avg(字段) from +表名;
查询某个字段最大值:
select max(字段) from +表名;
查询某个字段最小值:
select min(字段) from +表名;
对某个字段进行去重:
select distinct(字段) from +表名
备份表,备份数据,备份数据库,还原数据库
0.创建一个新表并备份源数据表,creat table 新表 select*from 源表
1.备份表,创建一个表与某个表相同         
create table +表1 like +表2

2.备份数据,把一个表的数据插入到另一个表
insert into +表名 select * from +表名
注意点:插入的表必须要存在

3.把一个表的某些字段插入到一个新表中
insert into +表1(字段1,字段2) select 字段1,字段2 from 表2

注意点
1. 插入的表必须存在
2. 插入的表是新表,没有数据。
4.备份数据库
mysqldump -uroot -p 数据库名 >脚本名

5.还原数据库
mysql -uroot -p +数据库 <脚本名



数据库用户权限操作
给普通的数据库用户赋予相应的权限
1.进入mysql数据库:use mysql;
2.查询mysql数据库服务器已经创建了哪些用户:select host,user from user;
3.创建用户但是未授权(方法一)
insert into user(host,user,password)values('localhost','wang',password('123456'));
创建用户后需要刷新下:flush privileges;

4.创建用户后进行授权(方法二)
grant select,update,delete,drop on *.* to 'wang'@'localhost' identified by
'123456

5、创建用户同时授权
grant all privileges on *.* to 'dcs'@'%' identified by '123456';
授予一个普通用户dcs及密码为123456,允许其可以通过所有客户机访问本
数据库下所有的库及所有的表,假如为localhost只能在本地进行访问。



6.查看数据库的指定授权用户的权限
show grants for 'wang'@'%';

7.取消所有权限
revoke all on *.* from 'dcs'@'%' ;
8.删除用户
delete from user where user='zhongguo'and host='localhost';
9. %:远程链接登录权限
localhost:本地登录

select database(); 查看使用的哪个数据库
select user(); 查看当前登录的用户
select version(); 查看数据库的版本
select now(); 查看数据库当前时间


分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册