MySQL数据库的一些总结和讲义
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,本文主要给大家介绍MySQL数据库的一些总结和讲义,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在行业资讯里面关注我的更新文章的。数据导入与导出(1)数据导入mysql>load d
千家信息网最后更新 2025年11月07日MySQL数据库的一些总结和讲义
本文主要给大家介绍MySQL数据库的一些总结和讲义,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在行业资讯里面关注我的更新文章的。
数据导入与导出(1)数据导入mysql>load data infile "目录/文件名" into table 表名 /默认目录为 /var/lib/mysql-files,可修改配置文件改变默认目录,如不修改配置文件,默认且一定要在这个目录下 >field terminated by "字段间隔符" /导入的文本数据的字段间隔符号 >lines terminated by "\n" /导入的文本数据的行结束符号mysql> show variables like "secure_file_priv"; 查看默认目录/etc/my.cnfsecure_file_priv="/myfile" 把/etc/passwd 数据导入到表user中 a.创建表user(表中字段要与导入的数据中字段相同) create table user( >name char(15), >passwd char(8), >uid int, >gid int, >comment varchar(50), >homedir varchar(30), >shell varchar(30), >index(name), >unique index(uid) >); b.把/etc/passwd 数据放入默认目录/var/lib/mysql-files cp /etc/passwd /var/lib/mysql-files/ c.数据导入 load data infile "/var/lib/mysql-files/passwd" into table user \ >fields terminated by ":" lines terminated by "\n"; /此表中字段间隔符为":",行结束符号为"\n". d.验证 select * from user; (2)数据导出 把表记录通过sql查询存储到系统文件中 >sql查询 into outfile "目录/文件名" fields terminated by "字段间隔符" lines terminated by "行结束符号" /目录默认/var/lib/mysql-files 如不修改配置文件,默认且一定要在这个目录下 #把uid小于100的数据导出到user1.txt文件中 >select * from user where uid < 100 into outfile "/var/lib/mysql-files/user.txt" \ >fields terminated by "*"\ /字段间隔符为 * >lines terminated by "#" /行间隔符为 ##################################################################################管理表记录增insert into 库名.表名 values(值列表),(值列表); /给所有字段赋值insert into 库名.表名(字段名列表) values(值列表),(值列表); /只给个别字段赋值查select * from 库名.表名; /查询表所有字段数据select 字段名列表 from 库名.表名 /查询个别字段数据#select name ,uid from user;select * from 库名.表名 where 条件;#select * from user where name="root"; /查询name字段为root的所有数据条件匹配的表示方式: 数值比较 > >= < <= = !=字符比较 = !=范围内匹配(a) 字段名 in (值列表) 在...里#select * from user where name in ("root","tom","apache"); /字段名匹配几个 查询几条(b)字段名 between 值1 and 值2 在...之间#select * from user where uid between 10 and 50; /字段名匹配几个 查询几条(c)not in#select * from user where name not in ("root","tom","apache"); /相当与 in 的取反,匹配的都不显示匹配空/非空(a) is null#select * from user where name is null;(b) is not null#select * fro user where name is not null;不显示重复值(a)distinct 字段名#select shell from user; /查询表中的shell字段数据 ,其中有很多重复值#select distinct shell from user /把重复的值只显示一次,可以快速查看此字段中都有那些数据逻辑匹配 : 有多个条件逻辑与 and 多个条件必须都成立逻辑或 or 多个条件有一个条件成立即可逻辑非 ! 取反#select name from user where name="tom" and uid=500; /查询 name字段为tom 且uid=500 ,显示name字段数据 条件都必须成立#select name from user where name="root" or uid=100; /查询name字段数据 其条件为 name="root" 或者uid=100数学运算操作 + - * / % 字段类型必须是数值类型#select uid,gid,uid+gid he from user; /查询 uid,gid 和uid+gid 和 的字段信息 he(uid+gid的值的字段名,可变)模糊查询where 字段名 like '表达式'(a)"_" 表示一个字符#select name from user where name like 'r_o_t'; /一个'_'表示一个字符(b) % 0个或多个字符#select name from user where name like 'r%'; /查询name字段r开头的所有数据#select name from user where name like '%r%'; /查询name字段包含r的数据#select name from user where name like '%t'; /查询name字段t结尾的所有数据#select name from user where name liek 'r%' or name like '%t'; /以r开头或者t结尾正则匹配where 字段名 regexp '正则表达式'#select name from user where name regexp '[0-9]'; /查询name字段中有数字的数据#select name from user where name regexp '^[0-9]'; /查询name字段中 数字开头的数据#select name from user where name regexp '^r'; /查询name字段中 r开头的数据#select name from user where name regexp 'r.*t'; /查询name字段中,r t之间包含0个或多个字符的数据统计函数 字段得是数值类型(a)sum(字段名) 求和#select sum(uid) from user;(b)avg(字段名) 平均值#select avg(uid) from user;(c)max(字段名) 最大值#select max(uid) from user;(d)min(字段名) 最小值#select min(uid) from user;(e)count(字段名) 统计个数#select sum(uid) from user; /不统计字段值为null 查询排序>sql查询 order by 字段名 /默认升序 desc 降序#select uid from user order by uid; /查询uid字段数据并升序排序#select uid from user order by uid desc; /查询uid字段数据并降序排序#select * from user order by uid; /查询表中所有数据并以uid升序排序查询分组>sql查询 group by 字段名 /把相同的数据放在group组里,相当于不显示重复值#select shell from user group by shell; 限制查询显示行数 (a)limit 数字n; 显示前n行#select * from user limit 3;#select * from user where uid between 10 and 50 limit 3;(b)limit 数字m,数字n; 显示m行后的n行#select * from user limit 1,2; 显示第1行后的两行内容 相当于显示2-3行内容#select * from user limit 1,1; 显示第二行内容嵌套查询 把内层的查询结果作为外层的查询条件select * from user where 条件 (select * from 表名 where 条件);#select * from user where name in (select name from user where uid<10);#select name,uid from user where uid > (select avg(uid) from user);复制表 作用:快速建表 、 备份表create table 表名 sql查询#create table user1 select name,uid,homedir from user limit 3; /把sql查询的结果作为新表的结构及数据,#create table user2 select name,uid,shell from user limit 4;多表查询select 字段名列表 from 表名列表;笛卡尔集#select * from user1,user2; /显示为 3*4 12 行,user1表的每一行对应user2表的每一行#select * from user1,user2 where user1.name=user2.name and user1.uid=user2.uid; /显示 user1 与user2 name,uid字段相等的行连接查询(a)左连接查询 以左边表(A)为主查询某个条件下 表A,表B的数据select * from 表A left join 表B on 条件;#select * from user1 left join user2 on user1.uid=user2.uid;(b)右连接查询 以左边表(B)为主查询某个条件下 表A,表B的数据#select * from user1 right join user2 on user1.uid=user2.uid;改修改某字段内的记录(a)update 表名 set 字段名="";#update user1 set uid=3;(b)update 表面 set 字段名="" where 条件;#update user2 set uid=2 where name="root";删删除记录(a)delete from 表名; /删除表中记录#delete from user1;(b)delete from 表名 where 条件; /删除某个条件下的一行记录#delete from user1 where name="root";
看了以上关于MySQL数据库的一些总结和讲义,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。
字段
查询
数据
条件
目录
文件
符号
一行
内容
升序
数字
排序
配置
数据库
讲义
相同
文件名
文本
查询表
结果
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
本溪app软件开发
海淀区品质软件开发价目表
织梦数据库服务器密码忘记了
家庭服务器安全吗
网络安全法由多少章 多少条
叨叨记账服务器无响应
河北天驱服务器虚拟主机
网络技术对行政的影响
软件开发现状调查报告
友戏互联网科技app
福建安全云空间工具服务器
谷歌软件开发工具
四川java微服务架构数据库
乡镇网络安全工作汇报
年画数据库中华木版
1软件开发的工作流程
网易2b2t服务器手机版最新版
互联网政府网络安全防护
潜江放心的软件开发方案
服务器允许软件连接外网
网络技术安全包括物理安全
软件开发后如何扩大业务
软件开发报考一建
软件开发公司实操
数据库的两个表关联
四川预算管理软件开发商
软件开发 人员 温州
魔兽世界数据库 大地裂变
必须用数据库吗
微服务器ip