Overview of MSQL database in Linux system

This section mainly learns the overview of MySQL database, database type, database model, steps to install MySQL with yum, and mysql login. mysql configuration


Table of contents

I. Overview

1. What is a database

2. What can the database do?

3. Why use a database, its advantages and features?

2. Database type

1. Relational database, RDBMS

2. Non-relational database, NoSQL

3. Database model

Four, MySQL installation (yum installation)

1.yum/rpm installation

①Download the installation package

②Install the database service

③Problem Solving

1. Installing mysql prompts that the public key is not installed

2. When logging in to the database, it prompts that the password is wrong

④Direct yum installation mariadb

Five, MySQL login

Six, MySQL configuration

1. Database directory structure

①rpm installation

② Source code installation

2. Detailed explanation of the main configuration file

/etc/my.cnf

Extend configuration items


I. Overview

1. What is a database

Save a large amount of data and process it through a computer to efficiently access the data collection

                                    bank deposit information phone book

2. What can the database do?

Enterprise application Store user data and manage enterprise data
Financial sector Store and analyze customer financial data
e-commerce Store product information, order information, etc.
social media Store social messaging data
internet of things Data storage of IoT devices on cloud service platform

3. Why use a database, its advantages and features?

reliability and stability Modern database systems usually have high reliability and stability, can provide persistence and fault tolerance, and can ensure the data security of enterprises.
Data management capability The database system provides a powerful way to manage data, from data storage to access to unified management. Businesses can better track, manage and report on data, making work more efficient.
Data Sharing and Integration Businesses often need to collect information and data from different departments and applications. Through the use of databases, these data can be integrated to make it easier for enterprises to understand business and make decisions.
Data Security and Privacy Protection Businesses often deal with large amounts of confidential data, such as personal information, financial information, business data, and more. The database management system can provide secure access control and data protection functions to protect the privacy and confidentiality of data.
Reduce data redundancy Database technology can help enterprises reduce data redundancy and duplication, and improve data consistency, accuracy and reusability.

2. Database type

1. Relational database, RDBMS

overview A relational database is a database that uses tables to display and manage data. The core of a relational database is the relationship between data, so it is also called a "relational database". RDBMS allows users to easily use and manage these relationships
features Easy to query and operate SQL statement
structured data Store data in rows and columns
Data Consistency and Integrity various constraints
concurrency Supports isolation of multi-user connections
Representative products MySQL Developed by MYSQL AB in Sweden, now managed by Oracle Corporation
PostgreSQL A free and open source database management system developed by the PostgreSQL global development team

2. Non-relational database, NoSQL

overview NoSQL (Not only SQL) is a non-relational database model whose data storage and query mechanism is different from traditional relational databases
features unstructured data text, images, media, etc.
distributed storage Distributed in multiple nodes to achieve high concurrency
no fixed canonical pattern No need to define tables and columns, no mandatory structure
high scalability Support horizontal expansion, add or delete nodes
high performance High-speed read and write operations are more efficient than traditional relational databases
Representative products MongoDB A non-relational database software based on the document storage model
Redis A non-relational database based on memory storage, which is widely used in the Internet field like MongoDB, and Redis is often used in scenarios such as fast read and write operations and caching

3. Database model

hierarchical database model In 1966 , IBM researcher Codd proposed a hierarchical structure model
whose data structure is like a tree structure. Each node has only one parent node, but can have multiple child nodes.
This model has problems such as complex hierarchical structure, poor scalability, and data operation limitations.
Grid-type database model In 1969, the CODASYL working group released the network model,
which uses complex linked lists to represent the relationship between data, and increases the flexibility and recursive processing capabilities of the data structure, thereby solving some problems of the hierarchical structure model
. some problems. However, the network model needs to understand the complex physical storage structure, which has relatively high requirements for programmers.
relational database model 1970年,Codd提出了关系型模型,也就是目前SQL和RDBMS所采用的模型
关系型模型基于二维表格的结构组织数据,每个表格称为关系,每行记录代表一个实体,每列记录代表一个属性。关系之间通过主键和外键进行关联
它具有数据结构简单、数据组织规范、数据操作强大、数据完整性可控等优点,是目前应用最广泛的数据库模型
非关系型模型

四、MySQL安装(yum安装)

1.yum/rpm安装

①下载安装包

wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

②安装数据库服务

rpm -ivh mysql57-community-release-el7-8.noarch.rpm

yum -y install mysql-server

 直接安装会出现MySQL没有公钥

③问题解决

1、安装mysql提示公钥未安装

提示信息 mysql-community-common-5.7.42-1.el7.x86_64.rpm 的公钥尚未安装
 失败的软件包是:mysql-community-common-5.7.42-1.el7.x86_64
 GPG  密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
分析原因 mysql密钥过期
解决办法 安装新的密钥然后再安装服务 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum -y install mysql-server
不使用GPG密钥验证 yum -y install mysql-server --nogpgcheck

 不使用GPG密钥验证:

2、登录数据库时提示密码错误

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

输入的密码是错误的,所以拒绝你的访问

使用随机密码登录 查看临时密码

grep 'temporary password' /var/log/mysqld.log

登录时使用查看到的随机密码

mysql -u root -p

 

Enter password: 输入随机密码

 

自行重置密码 重置密码的第一步就是跳过MySQL的密码认证过程 进入数据库的配置文件 vim /etc/my.cnf
添加参数,不验证密码进入mysql

skip-grant-tables

接下来我们需要重启MySQL systemctl restart mysqld
重新登录数据库时,直接按回车 查看数据库

                                                     show databases;

 

 使用mysql数据表

use  mysql;

                                                                          

创建root用户使用新的密码

create  user  'root'@'localhost' identified by '123456';

              

如果报错,先刷新配置,在删除原

来的root用户,然后再执行创建的操作

                              

flush privileges;

drop user 'root'@'localhost';

create  user  'root'@'localhost' identified by '123456';

赋予root权限

grant all privileges on *.* to 'root'@'localhost' with grant option;

 

刷新配置,退出数据库

flush privileges;

exit
恢复最开始的配置文件 vim /etc/my.cnf

去掉配置项skip-grant-tables

 

重启mysql,然后使用新密码重新登录数据库 systemctl restart mysqld

mysql -uroot -p123456

 

 登录时提醒

④直接yum安装mariadb

                                                                     yum -y install mariadb mariadb-server

不使用配置文件越过密码验证,修改密码    mysqladmin  -uroot -p password '新密码'

五、MySQL登录

本地登录    使用命令

借助软件登录    navicat

六、MySQL配置

1、数据库目录结构

①rpm安装

mysql:存储MySQL的数据文件和表结构定义等。

mysql-files:存放需要MySQL账户权限的文件。

mysql-keyring:存放加密密钥,以供MySQL使用。

mysql.sock:MySQL服务器的Unix套接字文件。

ib_logfile0和ib_logfile1:InnoDB引擎的事务日志文件。

ibdata1:InnoDB引擎的数据文件,包括表数据和索引等。

*.err:MySQL错误日志文件,记录MySQL运行时的错误和警告等信息。

*.pid:MySQL进程ID文件,存储MySQL进程的进程号。

②源码安装

   mysql-<version>/
    ├── extra/            # 额外的工具和脚本
    ├── include/            # 包含头文件
    ├── lib/            # 包含库文件
    │        ├── libmysqlclient.so    # MySQL 客户端库文件
    │        └── libmysqld.so    # MySQL 服务器端库文件
    ├── share/            # 包含共享文件
    ├── support-files/        # 包含初始化脚本和系统服务
    │        ├── mysql.server    # MySQL 服务启动脚本
    │        ├── mysql.service    # MySQL systemd 服务配置
    │        └── ...             # 其他各种脚本和配置文件
    ├── bin/            # MySQL 二进制文件
    │        ├── mysqld        # MySQL 服务器二进制文件
    │        ├── mysql        # MySQL 客户端二进制文件
    │        ├── mysqladmin    # 管理 MySQL 服务器的工具
    │        ├── mysqldump        # 导出 MySQL 数据库的工具
    │        └── ...            # 其他各种 MySQL 工具
    ├── man/            # MySQL 帮助手册
    ├── docs/             # MySQL 文档
    ├── sql/            # MySQL SQL 脚本文件
    └── zlib/            # MySQL 所依赖的 zlib 库

2、主配置文件详解

/etc/my.cnf

    [mysqld]       [mysqld]"表示该段配置是针对MySQL服务器的
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    log-error=/var/log/mysql/mysql-error.log
    pid-file=/var/run/mysql/mysql.pid
    max_connections=500
    character-set-server=utf8mb4
    collation-server=utf8mb4_unicode_ci
    [mysql]        [mysql]"中的配置项表示该段配置是针对MySQL客户端的
    default-character-set=utf8mb4

拓展配置项

    port:MySQL端口号
    log_warnings:设置错误日志是否记录警告信息
    slow_query_log_file:慢日志文件路径名
    long_query_time:当查询时间超过指定的秒数时,会被记录到慢日志中
    innodb_buffer_pool_size:InnoDB缓存池大小
    join_buffer_size:用于JOIN操作的缓存大小
    max_allowed_packet:MySQL允许传输的最大数据包大小
    skip_name_resolve:禁用DNS解析


Guess you like

Origin blog.csdn.net/lsqaa/article/details/131901875