MySQL1.数据库MySQL的简单的介绍与安装

1.MySQL
2. 数据库的介绍
2.1 数据是什么?
咱们认为:
账号密码、图片、视频、数字、特殊符号、文字、链接
计算机:
二进制数据
2.2 数据如何存储?
账号密码该怎么存储?
能存到excel?
可以存.会有什么问题?
安全。
存储限制。
2.3 数据库管理系统(DBMS)
RDBMS 关系型数据库
Oracle
MySQL
MSSQL
PG
NoSQL 非关系型数据库
MongoDB
ES
Redis
云数据库
RDS , PolarDB
TDSQL
NewSQL
TiDB
3. MySQL 产品线
3.1 MySQL 厂家
Oracle  官方
MariaDB
Percona
3.2 Oracle MySQL 企业版本选择
5.6  ****  :5.6.36 ,5.6.38 ,5.6.40 ...5.6.46 (GA时间 6-12月)
5.7  ***** :5.7.20 ,5.7.22,5.7.24 ,5.7.26 ,5.7.28
8.0  **    :8.0.11 ,8.0.17,8.0.18
C : 社区版 ,开源
E :企业版 ,收费
3.3 MySQL各种安装方式(Linux)
通用二进制版: 解压即用
rpm,yum版本: 下载rpm包或者配置yum源 (自己研究)
源码包      : 编译安装,非常慢。     (自己研究)
4. “手撕” MySQL 5.7.28 二进制包安装
4.1 环境准备
(1) 准备Centos 7.6 虚拟机
 IP:10.0.0.51/24  hostname:db01
[root@db01 ~]# hostname -I
10.0.0.51
[root@db01 ~]# hostname
db01
(2)清理历史环境
[root@db01 ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@db01 ~]# yum remove mariadb-libs -y
(3)创建用户和组
[root@db01 ~]# useradd mysql -s /sbin/nologin
[root@db01 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
(4)创建相关目录
#创建软件目录
mkdir -p /app/database/    
#创建数据目录
mkdir -p /data/3306/
#创建日志目录
mkdir -p /binlog/3306/
(5)设置权限
chown -R mysql.mysql /app/ /data/ /binlog
4.2 上传并解压 MySQL软件
cd /app/database/  
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
[root@db01 database]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
4.3 设置环境变量
vim /etc/profile
#添加一行:
export PATH=/app/database/mysql/bin:$PATH
#生效配置
source /etc/profile
[root@db01 mysql]# mysql -V
mysql  Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using  EditLine wrapper
4.4 初始化系统库表
mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
# 报错
mysqld: error while loading shared libraries: libaio.so.1:
cannot open shared object file: No such file or directory
#解决
[root@db01 app]# yum install -y libaio-devel
#再次运行
mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
===========初始化过程================
2020-02-12T03:35:50.633463Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-12T03:35:51.182171Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-02-12T03:35:51.283797Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-02-12T03:35:51.348374Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c43c2d36-4d48-11ea-97b4-000c298e182d.
2020-02-12T03:35:51.349580Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-02-12T03:35:52.410522Z 0 [Warning] CA certificate ca.pem is self signed.
2020-02-12T03:35:52.606235Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
=======================================
#容易遇到的报错
2020-02-12T03:37:38.952735Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-12T03:37:38.955417Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2020-02-12T03:37:38.955478Z 0 [ERROR] Aborting

扩展:
5.7 初始化方式
(1)mysqld --initialize
 1. 初始化完成后,会有12位临时密码  ,但是必须在使用MySQL之前重置这个密码。
    [Note] A temporary password is generated for root@localhost: qa&Ichsl.0B+
 2. 密码管理使用严格模式:3种密码复杂度放一放。
(2)mysqld --initialize-insecure
5.6 版本初始化方式
/app/database/mysql/scripts/mysql_install_db --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
4.5 配置文件设置
cat > /etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/app/database/mysql
datadir=/data/3306
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
EOF
4.6 准备MySQL启动脚本
[root@db01 app]# cd /app/database/mysql/support-files/
#拷贝mysql的启动脚本至系统软件管理目录中
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
#centos6
[root@db01 ~]# service mysqld start
Starting MySQL.Logging to '/data/3306/db01.err'.
 SUCCESS!
 service mysqld start /stop /restart
#centos7
[root@db01 ~]# chkconfig --add mysqld
[root@db01 ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@db01 ~]# systemctl start mysqld

5. MySQL体系结构及基础管理
5.1 MySQL 客户端/服务器工作模型(C/S)
(1)本地scoket链接方式:
socket=/tmp/mysql.sock
mysql -S /tmp/mysql.sock
说明: 只能在本地使用,不依赖于IP和端口
(2)远程TCPIP链接方式
mysql -uroot -p123 -h 10.0.0.51 -P 3306
5.2 服务器端:实例
实例: mysqld+工作线程+预分配的内存结构
功能: 管理数据
公司: boss+员工+办公室
5.3  mysqld程序结构
看图说话。

5.4 MySQL的逻辑结构(操作对象)
Linux
目录 : 名字   + 属性
文件 : 文件名 + 文件属性 + 文件内容
MySQL                  
库      库名 + 库属性                 
表      表名 + 表属性 + 表内容  + 列             
mysql> show databases;
mysql> use mysql
mysql> show tables;
mysql> desc user;

5.5 MySQL的物理存储结构
段 : 一个表就是一个段,可以由1个或者多个区构成
区 : 一个区(簇),默认1M,连续的64个pages
页 : 一个页,默认16KB,连续的4个OS block,最小的IO单元
 
 
 
 
 
 
 
原文地址:https://www.cnblogs.com/wx1899325/p/12985646.html