数据库的基础操作

数据库密码忘了怎么办?

1.进入/etc  cd etc

2.编辑my.cnf  vim my.cnf

在文件内容末尾加上:skip-grant-tables

保存退出  wq

3.重启mysql,然后 mysql -uroot -p 直接跳过密码登录数据库

 

DML:表数据

增删改查:

insert into、delete、update、select

insete into 表名 指定字段 values (插入的值);  ---如果没有指定字段就按表结构插入值

  # 例子:insete into stu name valuer ('张三');  ---往stu表中插入name为张三的数据

  # 例子:insete into stu name age valuer ('李四',18);  ---往stu表中插入name为李四,age为18的数据

delete from 表名 where 条件;

  # 例子:delete from stu where name is null;  ---删除stu表中name为空的数据

  # 例子:delete from stu where name = '张三';  ---删除stu表中name为张三的数据

  # 例子:delete from 表名;  ---清空表数据

update 表名 set 需要修改的字段值 where 条件;  

  # update b set 需要修改的字段值 where 条件是A与B表相互联系and A表中某一个字段值等于xx;

select 搜索内容 from 表名 where 条件;

  # 例子:select * from stu where name = '张三';   ---查询stu表中name为张三的所有数据

 

DDL:表库的操作

增删改查:

create databse 库名;  ---创建库

create table 表名;   ---创建表

alter table 表 add 新字段 数据类型;   ---新增字段

drop table 表名;   ---删除表

alter table 表 change 原字段名 新字段名 数字类型;  ---修改表字名

alter table 旧表名 rename 新表名;  ---修改表名

show databases/tables;   ---查看库/表

desc 表名;   ---查看表头(表结构)

 

多表连接:

stu:id,name,sex,age

cjb:id,cj,hobby

select * from stu,cjb where stu.id=cjb.id;  ---基本连接

select * from stu inner join cjb on stu.id=cjb.id;  ---内连接

select * from stu left join cjb on stu.id=cjb.id;  ---左连接

select * from stu right join cjb on stu.id=cjb.id;  ---右连接

 

常见索引:

普通索引、唯一索引、主键索引、组合索引、全文索引

索引的作用:加快查询速度、读取速度、保证数据记录的唯一性,实现表与表之间的参照完整性

 

redis特性:

1.速度快

2.基于k_v的数据结构

3.功能相对丰富

4.简单稳定

5.客户端语言多

6.持久化

7.主从复制

8.高可见和分布式

 

posted @ 2022-11-02 16:27  真小白!  阅读(55)  评论(0)    收藏  举报