RDBMS关系型数据库管理系统
一、RDBMS关系型数据库管理系统
1、数据存储结构
数据库
表
记录 record, 每一行数据
字段 column, 列名
2、约束 constraint
1)、域约束【必须】
在字段进行数据类型限制
作用: 确保表中的某个字段的数据格式统一
2)、检查性约束
作用: 确保数据的合理性
3)、主键约束 primary key
作用:确保某一行的数据的惟一性
不允许出现重复数据
不允许为空
注意: 一张表只能有一个主键
4)、惟一键约束 unique key
不允许重复、允许为空
一张表中可以存在多个惟一键
5)、外键约束 Foreign Key
作用: 确保数据的完整性
3、关系型数据库管理系统的软件
开源软件
MySQL、PostgreSQL
MariaDB
商业数据库
Oracle
SQL Server
国产数据库
阿里 OceanBase
华为 GuassDB
达梦
人大金创
二、MySQL 8.0安装部署
1、安装MySQL软件仓库
- 使用mysql官方源
[root@node01 ~]# wget https://repo.mysql.com/mysql80-community-release-el7.rpm
--2024-10-30 11:41:49-- https://repo.mysql.com/mysql80-community-release-el7.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.111.200.167, 2600:140b:2c00:aa8::1d68, 2600:140b:2c00:aac::1d68
Connecting to repo.mysql.com (repo.mysql.com)|104.111.200.167|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14064 (14K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7.rpm’
100%[==============================================================>] 14,064 --.-K/s in 0s
2024-10-30 11:41:51 (455 MB/s) - ‘mysql80-community-release-el7.rpm’ saved [14064/14064]
[root@node01 ~]# ls
mysql80-community-release-el7.rpm nginx-1.27.2 nginx-1.27.2.tar.gz
[root@node01 ~]#
[root@node01 ~]# rpm -ivh mysql80-community-release-el7.rpm
warning: mysql80-community-release-el7.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-11 ################################# [100%]
- 使用内网FTP源安装MySQL
[root@node01 ~]# cat /etc/yum.repos.d/mysql80.repo
[mysql80]
name=mysql80
baseurl=ftp://10.11.0.254/software/mysql8.0.37/
enabled=1
gpgcheck=0
2、安装MySQL 8.0
[root@localhost ~]# yum install -y mysql-community-server
[root@node01 ~]# rpm -qa | grep mysql
mysql-community-common-8.0.37-1.el7.x86_64
mysql-community-icu-data-files-8.0.37-1.el7.x86_64
mysql-community-client-8.0.37-1.el7.x86_64
mysql-community-libs-8.0.37-1.el7.x86_64
mysql-community-client-plugins-8.0.37-1.el7.x86_64
mysql-community-server-8.0.37-1.el7.x86_64
3、启动MySQL服务
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld
[root@node01 ~]# netstat -tunlp | grep mysql
tcp6 0 0 :::33060 :::* LISTEN 10387/mysqld
tcp6 0 0 :::3306 :::* LISTEN 10387/mysqld
[root@node01 ~]# ps -elf | grep mysql
4 S mysql 10387 1 33 80 0 - 572443 poll_s 11:48 ? 00:00:11 /usr/sbin/mysqld
0 S root 10747 9908 0 80 0 - 28203 pipe_w 11:49 pts/0 00:00:00 grep --color=auto mysql
4、修改root用户密码
[root@web ~]# grep -i "password" /var/log/mysqld.log
2023-08-17T07:39:00.876344Z 1 [Note] A temporary password is generated for root@localhost: kjFL%6Iiy_sp
[root@web ~]#
[root@web ~]# mysql -u root -p
Enter password:
mysql> alter user 'root'@'localhost' identified by 'WWW.1.com';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
5、测试连接登录数据库
[root@localhost ~]# mysql -uroot -pWWW.1.com
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
三、MySQL配置文件解析
1、配置文件 ---- /etc/my.cnf
-
datadir=目录
指定数据目录
数据目录的属主、属组必须为mysql用户 -
socket=/var/lib/mysql/mysql.sock
套接字文件
作用: 接收本地客户端的访问请求
如果要修改套接字文件的位置,会影响客户端的连接登录,为方便客户端连接登录,可以在配置文件中为客户端指定套接字文件
[client]
socket=/mysql/data/mysql.sock
-
log-error=
指定错误日志 -
pid-file=
指定pid文件