mysql数据更新、单表查询
1.数据插入
insert into student(name,age)values(‘zhangsan’,18)
2.删除数据
delete from student where name = ‘zhangsan’
3.更新数据
update student set class = 1899 where name=‘zhangsan’
4.单表查询
select * from student 查询表中所有数据
select age from student where name = ‘zhangsan’ 查询student中张三的年龄
select * from student limit(1,2)查询表中第一行开始下面两行的数据
select * from student group by class = 1899 having name = ‘小乔’; 先以班级分组再查询出小乔的数据
select * from student order by age asc/desc;查询出以age的升序/降序
5.聚合函数
select count(id)from student;统计id的数量
sum(id)、avg(id)、max(id)、min(id) #求和、平均值、最大值、最小值
select distinct(id)from student 对id去重
6.备份表
create table student like student1; 复制表结构
7.备份表数据
insert into student1 select * from student;
8.备份、还原数据库
mysqldump -uroot -p 数据库名 >脚本名 数据备份
mysql -uroot -p 数据库<脚本名 数据还原
9.数据库用户权限
select host,user from user;查询创建了哪些用户
insert into user(host,user,password)values(‘localhost’,‘sansan’,‘123456’);#新增本地用户sansan,密码123456
mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to "用户名"@"用户地址" identified by "连接口令";
grant all privileges on *.* to 'sansan'@'%' identified by'123456'; #授予一个普通用户sansan及密码为123456对所有数据库和所有表的全部权限,第一个*表示所有数据库,第二个*表示所有表
flush privileges;赋权后要刷新权限

浙公网安备 33010602011771号