Mysql系列课程--第四章 备份 普通查询

查询涉及到的数据请查看:
Mysql系列课程–第三章 建表 插数据

一.数据库备份与还原

 mysqldump -uroot -proot --databases yz  >  /home/test/yz.sql

备份多个数据库:

mysqldump -uroot -proot --databases yz  myschool  >  /home/test/yz.sql

数据库还原:

   mysql -uroot -proot < /home/test/JavaCourse/mysql/xiaoshuai.sql

二.自增主键的重新排序(不存在外键关联)

alter table student drop column s_no;
alter table student add column s_no int primary key auto_increment first;

三.普通查询

1.算术运算(as 起别名,可以省略)

select s_name,s_age*3+1 as '你能活到多大' from student;
select * from student where s_no = 2 + 1;

2.比较运算符

select * from student where s_sex <> '男';
select * from student where s_age > 30;
select * from student where s_age >=20 and s_age<=30;
select * from student where s_age between 20 and 30;
select * from student where s_age in (20,30,25);
select * from student where s_sex is null;
select * from student where s_name like '_大%';
select * from student where s_name regexp '.大';

3.逻辑运算符

select * from student where not s_sex='男';
select * from student where not s_sex='男' and s_age>20;
select * from student where s_age = 20 or s_age = 30;
select * from student where s_age != 20 xor s_age != 30;

4. in 与 or 的区别
没有区别,可以互换,当数据量小的时候用or,数据量大用in

select * from student where s_age in (20,30);
select * from student where s_age = 20 or s_age = 30;

5./找出20岁以上男人,20岁以下女人/

select * from student where s_sex='男' xor s_age<20;
select * from student where (s_sex='男' and s_age>=20) or (s_sex='女' and s_age<20);
select * from student where (s_sex='男' && s_age>=20) || (s_sex='女' && s_age<20);
(mysql支持 &&这样的查询方法 , 但是标准的sql是不支持的.)

四.字符串常用函数

1.连接字符串

select concat(s_name,'学生') from student;

2.字符串替换(位置从1开始)

select  insert(s_name,1,2,'藏獒')  from student where s_name='葬爱勇少';

3.转换成大写

select upper(s_name) from student where s_name= 'a';

4.首尾拼接

select  lpad(s_name,7,'傻傻的')  from student where s_name='葬爱勇少';
select  rpad(s_name,7,'傻傻的')  from student where s_name='葬爱勇少';

5.截取

select substring(s_name,1,2)  from student where s_name='葬爱勇少';

6.字段去重

select  distinct  s_sex from student;

详细课程查询:
Mysql系列课程–第一章 Sql分类 常用命令
Mysql系列课程–第二章 约束 自增主键
Mysql系列课程–第三章 建表 插数据
Mysql系列课程–第四章 备份 普通查询
Mysql系列课程–第五章 高级查询 表连接 子查询 case when
Mysql系列课程–第六章 索引和视图
Mysql系列课程–第七章 触发器和存储过程
Mysql系列课程–第八章 sql精选35道题

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值