数据库结构

SQL数据库(关系型)

1.收费

1.DB2
2.Sqlserver
3.Oracle

2.开源免费

1.Mysql
2.Sqlite(所有语言默认支持的数据库,数据库小)
3.Postgresql(Linux)

NOSQL数据库(非关系型)

非关系数据库是为了弥补关系型数据库而诞生的。
1.MongoDB
2.Redis
3.Memcache

LAMP环境

1.Linux
2.Apache
3.Mysql
4.PHP

5.js+node.js+mongodb

数据库基本结构

1.数据库服务器:

1.数据库
2.数据表

2.数据表:

1.表结构(字段)
2.表数据(记录)
3.表索引(加快检索)

3.表引擎(Mysql为例):

1.myisam(3个文件)
2.innodb(2个文件,还有一个文件(这个文件只有一部分))

4.Mysql 基本命令

1.登陆mysql
mysql -uroot -p123456;
2.如何查看数据库
show databases;
3.切换数据库
use 库名;
4.查看所有表
show 库名;
5.查看表中的字段
desc 表名;
6.查看表里的数据
select * from 表名;
7.退出mysql
exit;

扫描二维码关注公众号,回复: 6219373 查看本文章

5.数据库操作:

1.创建数据库
create database 库名
2.删除数据库
drop database 库名

6.表操作:

1.创建表
create table 表名(
id int,
username varchar(50),
age int,
PRIMARY KEY(id)
)

2.删除表
drop table 表名

7.表数据操作:

1.插入数据
insert into 表名(字段,字段,字段) values(1,‘user1’,20);
2.删除数据
delete from 表名 where 条件
3.修改数据
update 表名 set 字段=value where 条件
4.查看数据
select * from 表名

8.表索引:

1.主键索引
2.唯一索引
3.普通索引

索引作用:

提高检索速度

1.普通索引:

1.增
alter table 表名 add index 索引名 (字段名);
2.删
alter table 表名 drop index 索引名;

2.唯一索引:

1.增
alter table 表名 add unique 索引名(字段名);
2.删
alter table 表名 drop index 索引名;

3.主键索引:

1.增
alter table 表名 ADD PRIMARY KEY(字段); 更改表架构设定主键。
2.删
alter table 表名 modify id int unsigned not null; 先删除自增
alter table 表名 drop primary key;

9.数据库基本操作:

select * from 表名 where id=1\G 不能加分号

1.表名的反引号作用:

可以有效的屏蔽关键字问题(表名和字段名不允许使用关键字)

2.修改数据表字段:

1.增

alert table 表名 add sex tinyint not null after 字段名;
alert table 表名 add sex tinyint not null after 字段名 after 字段名; 放在哪个字段下面
alert table 表名 add sex tinyint not null after 字段名 first; 放在最上面

2.删

alert table 表名 drop sex;

3.改

alter table 表名 change 字段名 要改的名字;

猜你喜欢

转载自blog.csdn.net/qq_39649585/article/details/90167952