行业知识
1. MySQL 5.7安装部署
2026-11-06 17:53:52
来源:互联网转载
RDBMS关系型数据库管理系统
- 一、RDBMS关系型数据库管理系统
- 1、数据存储结构
- 2、约束 constraint
- 1)、域约束
- 2)、检查性约束
- 3)、主键约束 primary key
- 4)、惟一键约束 unique key
- 5)、外键约束 Foreign Key
- 3、关系型数据库管理系统的软件
- 二、MySQL 5.7安装部署
- 1、安装MySQL软件仓库
- 2、安装MySQL 5.7
- 3、启动MySQL服务
- 4、修改root用户密码
- 5、测试连接登录数据库
- 6、在防火墙中放行数据库服务
- 三、MySQL配置文件解析
- 1、配置文件 ---- /etc/my.cnf
一、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 5.7安装部署
1、安装MySQL软件仓库
[root@web ~]# wget http://repo.mysql.com/mysql57-community-release-el7.rpm [root@web ~]# rpm -ivh mysql57-community-release-el7.rpm warning: mysql57-community-release-el7.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing... ################################# [100%]Updating / installing... 1:mysql57-community-release-el7-11 ################################# [100%][root@web ~]# ls /etc/yum.repos.d/CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo mysql-community.repo
[root@web ~]# sed -ri '/gpgcheck/s|1|0|g' /etc/yum.repos.d/mysql-community.repo[root@web ~]# sed -ri '/gpgkey/d' /etc/yum.repos.d/mysql-community.repo
2、安装MySQL 5.7
[root@localhost ~]# yum install -y mysql-community-server
3、启动MySQL服务
[root@localhost ~]# systemctl start mysqld[root@localhost ~]# systemctl enable mysqld[root@localhost ~]# netstat -antp | grep mysqltcp6 0 0 :::3306 :::* LISTEN 7620/mysqld [root@localhost ~]# ps -elf | grep mysql1 S mysql 7620 1 0 80 0 - 296199 poll_s 10:42 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
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 -pEnter 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> exitBye
5、测试连接登录数据库
[root@localhost ~]# mysql -uroot -pWWW.1.commysql: [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 5Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exit
6、在防火墙中放行数据库服务
[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp success[root@localhost ~]# firewall-cmd --reloadsuccess[root@localhost ~]# firewall-cmd --list-allpublic (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 3306/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
三、MySQL配置文件解析
1、配置文件 ---- /etc/my.cnf
-
datadir=目录
指定数据目录
数据目录的属主、属组必须为mysql用户
-
socket=/var/lib/mysql/mysql.sock
套接字文件
作用: 接收本地客户端的访问请求
如果要修改套接字文件的位置,会影响客户端的连接登录,为方便客户端连接登录,可以在配置文件中为客户端指定套接字文件
[client]
socket=/mysql/data/mysql.sock
-
log-error=
指定错误日志
-
pid-file=
指定pid文件
-
-
- 1、配置文件 ---- /etc/my.cnf