1. MySQL 5.7安装部署

一、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: NOKEY
Preparing...                          ################################# [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 mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      7620/mysqld         

[root@localhost ~]# ps -elf | grep mysql
1 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 -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

6、在防火墙中放行数据库服务

[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp 
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (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文件

  • 15
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于在 CentOS 上安装部署 MySQL 5.7.41,您可以按照以下步骤进行操作: 1. 确保您的 CentOS 系统已经安装了 `wget` 和 `tar` 工具。如果没有安装,可以使用以下命令进行安装: ``` sudo yum install wget tar ``` 2. 使用 `wget` 下载 MySQL 5.7.41 的二进制版本。您可以从 MySQL 官方网站下载适用于 CentOS 的二进制版本,例如: ``` wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz ``` 3. 解压下载的二进制文件: ``` tar -zxvf mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz ``` 4. 移动解压后的文件夹到 `/usr/local` 目录下: ``` sudo mv mysql-5.7.41-linux-glibc2.12-x86_64 /usr/local/mysql ``` 5. 创建 MySQL 数据存储目录: ``` sudo mkdir /usr/local/mysql/data ``` 6. 授权 MySQL 数据存储目录给 MySQL 用户: ``` sudo chown -R mysql:mysql /usr/local/mysql/data ``` 7. 初始化 MySQL 数据库: ``` cd /usr/local/mysql sudo ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ``` 8. 启动 MySQL 服务: ``` sudo ./bin/mysqld_safe --user=mysql & ``` 9. 设置 MySQL 环境变量: ``` echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bashrc source ~/.bashrc ``` 10. 运行 MySQL 安全脚本以加强安全性并设置 root 用户密码: ``` sudo ./bin/mysql_secure_installation ``` 11. 您现在应该可以通过以下命令登录到 MySQL: ``` mysql -u root -p ``` 这些步骤将帮助您在 CentOS 上安装部署 MySQL 5.7.41。请注意,这只是基本的安装步骤,您可能还需要根据您的实际需求进行其他配置和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值