文章目录

  • 简述
  • 关系型数据库
  • 非关系型数据库
  • mariadb安装使用
  • mariadb数据
  • 计算机英语


简述

数据库简单来说就是一个存放数据的仓库,通过按照一定的数据结构来组织存储数据,而我们也可以通过数据库提供的多种方法来管理数据库里的数据。
数据库分为关系型数据库和非关系型数据库

关系型数据库

关系型数据库是把所有复杂的数据结构都归结为简单的二元关系,即二维格式表。在关系型数据库中,对数据的操作几乎全部建立在几个关系表上,通过对这些关联表格分类,合并,连接和选取来实现数据的管理。
优点:

  • 易于维护,都是使用表结构,格式一致
  • 使用方便,SQL语言通用,可用于复杂查询

缺点:

  • 读写性能较差,特别是应对海量数据时读写效率较低
  • 结构固定,灵活度低

常见关系型数据库:oracle,db2,sqlserver,mysql,mariadb

非关系型数据库

非关系型数据库并不是彻底否定关系型数据库,而是作为传统关系型数据库的一个补充,在特定场景可以发挥出难以想象的高效。
非关系型数据库严格意义上不是一种数据库,而是一种数据结构化存储方法的集合。
优点:

  • 格式灵活,不拘泥于表,可以是key,value,文档,图片等等
  • nosql可以使用硬盘或任意存储器作为载体,而关系型数据库只能使用硬盘
  • nosql数据库部署简单,多数是开源软件

缺点:

  • 不能使用SQL语言
  • 数据结构复杂,查询较慢

常见的非关系型数据库:mongodb,redis

mariadb安装使用

下载mariadb千万不要用官方的源(亲测,下到明年也下不下来),建议换成中科院的源

[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

安装好后进行设置,包括设置密码,是否禁止匿名用户登录,是否禁止root远程登录,是否重新加载权限表。

[root@101 yum.repos.d]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

mariadb提供mysqld服务,但mariadb还需要许多客户端程序来保证数据库工作进行。

tcp6       0      0 :::3306                 :::*                    LISTEN      10229/mysqld

客户端程序

mysql

交互式的client工具

mysqldump

数据库备份工具,基于mysql协议向mysqld服务发起查询请求,并将查询到的所有数据转换成insert等写操作语句保存在文件中

mysqladmin

基于mysql协议管理mysqld

mysqlimport

数据导入工具

其中我们最常用的客户端程序就是mysql

mysql -u

user

指定登录用户

mysql -p

password

指定登录密码

mysql -h

host

远程登录数据库

mysql -P

port

指定端口

mysql -e ‘SQL语句’

非交互式的使用SQL语句

mariadb数据

数据类型

整数

int,bit

精确值

decimal

字符串

char,varchar

日期时间

date,time,datetime

枚举

enum

数值类型

字节大小

signed有符号范围

unsigned无符号范围

tinyint

1

-128~127

0~255

smallint

2

-32768~32767

0~65535

mediumint

3

-8388608~8388607

0~16777215

int/integer

4

bigint

8

字符串类型

字节大小

char

0~255

占用字符固定

varchar

0~255

占用字符随具体字符数变化

text

0~65535

大文本

日期时间类型

字节大小

示例

date

4

2019-08-28

time

3

19:25:46

datetime

8

2019-08-28 19:25:46

year

1

2019

timestamp

4

‘2018-01-01 00:00:01’ UTC ~ ‘2019-01-01 00:00:01’ UTC

约束

主键

primary key

物理存储的顺序

非空

not null

该字段不能为空

唯一

unique

该字段不允许重复

默认

default

不填写时即为默认值

外键

foreign key

对关系字段进行约束,填写时会在关联的表中查询,如果查到则填写成功,没有查到则填写失败并返回异常

计算机英语

secure

安全

installation

安装

dump

倾倒

import

输入

integer

整数

enumerate

枚举

primary


unique

独特