导入导出操作:
将文本数据转入到数据库
文本数据的格式为【字段之间的数据采用tab键分割,一行对应一行数据】
3 张三 1989-2-3
4 李四 2020-5-12
创建对应的表,表结构应该对应文本文件中的数据
create table tb_users(
id int primary key,
name varchar(20) not null,
birth date
) engine=innodb default charset utf8;
导入语句,由于是在sql中直接进行读取硬盘文件,会涉及安全性配置问题
load data infile "d:/work.txt" into table tb_users(id,name,birth);
备份数据库
mysqldump --pt test>test.sql
恢复数据库,只创建一个空数据库
test
即可
mysql -uroot -p123456 test<test.sql
MySQL
运算符:
MySQL运算符主要包括
3
大类:比较运算符、算术运算符、逻辑运算符
算术运算符:
加+
、减
-
、乘
*
、除
/
、求余
%
mysql> select 1+2;
+-----+
| 1+2 |
+-----+
| 3 |
+-----+
1 row in set (0.00 sec)
mysql> select 1/2;
+--------+
| 1/2 |
+--------+
| 0.5000 |
+--------+
1 row in set (0.00 sec)
mysql> select 5%2;
+------+
| 5%2 |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
特殊操作 :
mysql> select '5a'+2;
+--------+
| '5a'+2 |
+--------+
| 7 |
+--------+
1 row in set, 1 warning (0.00 sec)
mysql> select 'a5'+2;
+--------+
| 'a5'+2 |
+--------+
| 2 |
+--------+
1 row in set, 1 warning (0.00 sec)
mysql> select 123.45%2.52;
+-------------+
| 123.45%2.52 |
+-------------+
| 2.49 |
+-------------+
1 row in set (0.00 sec)
mysql> select -123.45%2.52;
+--------------+
| -123.45%2.52 |
+--------------+
| -2.49 |
+--------------+
1 row in set (0.00 sec)
比较运算符:
运算符
|
语法
|
说明
|
= |
a=b
|
如果参与计算的两个操作数相等则为
true
,否则
false
|
!=
或者
<>
|
a!=b
或者
a<>b
|
如果两个操作数不相等则
true[1]
,否则
false[0]
|
<
|
a<b
|
如果
a
小于
b
则返回
true
,否则
false
|
>
|
a>b
|
如果
a
大于
b
则
true
|
<=
|
a<=b
|
小于等于
|
>=
|
a>=b
|
大于等于
|
in
或者
not in:
in用于判断某个列的取值是否为指定的值,使用
in
运算符时指定的值是离散的数据,不是连续值
①select * from tb_student where age in(18,28,15)
含义是
age=18 or age=28 or age=15
②select * from tb_student where age not in(18,28,15)含义是 age!=18 and age!=28 and
age!=15
③
--
查询张三以及李四同学的成绩
select score from tb_student where name='张三' or name='
李四
'
select score from tb_stuent where name in('张三','
李四
') -- in
中的数据个数没有限制
between/and
用于判断数据是否在指定的范围内,连续值
查询成绩及格并且不属于优秀的所有学生信息
-- 写法1:使用条件拼接
select * from tb_student where score>=60 and score<=85;
-- 写法2
select * from tb_student where score between 60 and 85;
--如果需要的是不在指定范围内部
select * from tb_student where score not between 50 and 85;
like/not like
主要针对字符串类型数据进行模糊查询,通配符_
和
%
查询不姓张的同学:
select * from tb_student where name not like '张%'
regexp是在
mysql
中针对字符串类型进行正则式进行判断,
not regexp
<=> 如果两数相同为
true
,即使是
null
is null/is not null
判断是否为空,为空则返回true
逻辑运算符:
运算符 |
语法
|
说明
|
&&
或者
and
|
a and b
或者
a&&b
|
逻辑与,如果参与计算的两个操作数为
true
,否则
false
|
||
或者
or
|
a or b
或者
a||b
|
逻辑或,如果参与计算的双反,只要一方为
false
,则返回
false
|
not
或者
!
|
not a
或者
!a
|
逻辑非,如果操作数为
false
则结果为
true
|