The basic concept and installation of Mysql database-super detailed! ! !

One, the basic concept of the database

1. Data

  • Symbol record
  • Including data, text, graphics, images, sounds, file records, etc.
  • Store in a unified format in the form of "records"

2. Table

  • Organize different records together
  • Used to store specific data

3. Database

  • A collection of tables is a warehouse for storing data
  • A collection of related data stored in a certain organization
    Insert picture description here

4. Database Management System (DBMS)

  • It is a system software that realizes effective organization, management and access to database resources

5. Database system

  • It is a man-machine system consisting of hardware, os, database, DBMS, application software and database users
  • Users can operate the database through DBMS or applications
    Insert picture description here

2. History of database system development

1. The first generation database

  • Since the 1960s, the first generation of database systems came out
  • It is a database system of hierarchical model and network model
  • Provides strong support for unified management and sharing of data

2. The second generation database

  • In the early 1970s, the second generation of databases-relational databases began to appear
  • In the early 1980s, IBM's relational database system DB2 came out, and began to gradually replace hierarchical and mesh model databases, becoming the mainstream of the industry
  • So far, relational database systems have occupied the main position of database applications

3. The third generation database

  • Since the 1980s, new database systems adapting to different fields have continuously emerged. Object-oriented database systems have strong practicability and wide adaptability.
  • In the late 1990s, a situation in which multiple database systems jointly supported applications was formed
  • Some new elements have been added to the mainstream database system
  • For example, the "relation-object" database model supported by Oracle

3. Today's mainstream databases

1. Introduction to mainstream databases

SQL Server (product of Microsoft Corporation)

  • For Windows operating system
  • Simple and easy to use

Oracle (Oracle company product)

  • For all major platforms
  • Safe, perfect, complicated operation

DB2 (product of IBM)

  • For all major platforms
  • Large, safe and complete

MySQL (acquired by Oracle)

  • Free, open source, small size
    Insert picture description here

2. Relational database

Relational database-1

  • Relational database system is a database system based on relational model
  • The data structure of the relational model uses a simple and easy to understand two-dimensional data table
  • The relational model can be represented by a simple "Entity-Relationship" (ER) diagram
  • The ER diagram contains three elements: entity (data object), relationship and attribute
    Insert picture description here

Relational database-2
entities

  • Also called an instance, it corresponds to an "event" or "thing" that can be distinguished from other objects in the real world
    • Such as bank customers, bank accounts, etc.

Attributes

  • A certain characteristic of an entity, an entity can have multiple attributes
    • For example, each entity in the "bank customer" entity set has attributes such as name, address, and telephone number

contact

  • Correspondence between entity sets is called connection, also called relationship
    • For example, there is a "savings" relationship between bank customers and bank accounts

The collection of all entities and their connections constitutes a relational database

Relational database-3

  • The storage structure of the relational database is a two-dimensional table
  • In each two-dimensional table
    • Each row is called a record, used to describe the information of an object
    • Each column is called a field, used to describe an attribute of the object
      Insert picture description here

3. Relational database applications

Relational Database

  • Oracle,MySQL
  • SQLServer、Sybase
  • lnformix、access
  • DB2、FoxPRO

Application examples

  • 12306 User Information System
  • Taobao account system
  • Unicom mobile phone number information system
  • Bank User Account System
  • Website User Information System

4. Introduction to non-relational databases

Non-relational databases are also called NoSQL (Not Only SQL)

The stored data is not based on the relational model and does not require a fixed table format

Advantages of non-relational databases

  • The database can be read and written with high concurrent
  • Efficient storage and access to massive data
  • Database has high scalability and high availability

Commonly used non-relational databases: Redis, mongoDB, etc.

5. Introduction to MySQL database

  • A popular open source relational database
  • Oracle products
  • Comply with GPL agreement, free trial and modification

Features:

  • Excellent performance and stable service
  • Open source, no copyright restrictions, low cost
  • Multi-threaded, multi-user
  • Based on C/S (client/server) architecture
  • Safe and reliable

6. MySQL Business Edition and Community Edition

  • MySQL Business Edition is developed and maintained by MySQL AB, and requires payment to use
  • MySQL Community Edition is developed and maintained by MySQL developers and enthusiasts scattered all over the world, and can be used for free

The difference between the two:

  • The commercial version has stricter organization management and testing and will be more stable than the community version
  • The commercial version does not comply with the GPL, and the community version complies with the GPL and can be used for free
  • The commercial version can get 7*24 hours of service, while the community version does not

7. MySQL product camp

  • The first camp: 5.0-5.1 camp, can be said to be the continuation of early products

  • The second camp: The 5.4-5.7 camp integrates storage engines developed by MySQL AB, the community, and third-party companies to improve performance

  • The third camp: 6.0-7.1 camp, which is the MySQL Cluster version, developed to meet the needs of database clustering in the new era

    • Download URL
      http://www.dev.mysql.com/downloads

Fourth, install Mysql5.7 database

Prepare the installation package Mysql package
Insert picture description here
1. Install the dependent package

[root@server1 ~]#yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

2. Create a non-loginable user

[root@server1 ~]# useradd -s /sbin/nologin mysql

3. Unzip the Mysql package

[root@server1 ~]#tar -zxvf mysql-boost-5.7.20.tar.gz

4. cmake configuration

[root@server1 ~]#cd mysql-5.7.20/
[root@server1 mysql-5.7.20]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \              #安装目录 安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \   #指定套接字文件的存储路径套接字:客户端访问mysql数据库的一个接口
-DSYSCONFDIR=/etc \                                     #配置my. cnf的目录 配置文件路径,(根目录)
-DSYSTEMD_PID_DIR=/usr/local/mysql \          #主服务进程所在路径 (进程文件目录)
-DDEFAULT_CHARSET=utf8 \                           #默认字符集
-DDEFAULT_COLLATION=utf8_general_ci \      #默认编码
-DWITH_INNOBASE_STORAGE_ENGINE=1 \     #启用InnoDB引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \        #启用ARCHIVE引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \   #启用BLACKHOLE引擎
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \  #启用perfschema引擎
-DMYSQL_DATADIR=/usr/local/mysql/data \    #数据存储路径  (数据库目录)
-DWITH_BOOST=boost \              #boost库是为C++语言标准库提供扩展的一些C++程序库的总称
-DWITH_SYSTEMD=1                 #这是mysql5.7原生支持systemd的选项,如果用systemctl启动,就必须开启

5. Compile and install

make && make install

6. Edit the configuration file

[root@server1 ~]# vi /etc/my.cnf

[client]      客户端
port = 3306  访问端口
default-character-set = utf8  默认字符集
socket = /usr/local/mysql/mysql.sock  套接字
[mysql]    运行用户
port = 3306  运行端口
default-character-set = utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]  程序
user = mysql   运行用户
basedir = /usr/local/mysql  根目录
datadir = /usr/local/mysql/data   用户目录
port = 3306  
character_set_server = utf8
pid-file = /usr/local/mysql/mysqld.pid   服务器配置字符
socket = /usr/local/mysql/mysql.sock   进程文件
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

7. Database authority configuration, owner, group

[root@server1 mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
[root@server1 mysql-5.7.20]# chown mysql:mysql /etc/my.cnf

Insert picture description here
8. Initialize the database

[root@server1 ~]# mysqld \
--initialize-insecure \             #生成一个空密码,不配置系统会自动生成一个密码
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

Insert picture description here
9. Copy files and start the service

[root@server1 ~]# cd /usr/local/mysql/
[root@server1 mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
[root@server1 mysql]# cd
[root@server1 ~]# systemctl enable mysqld
[root@server1 ~]# systemctl start mysqld
[root@server1 ~]# systemctl status mysqld

10. Set a password

[root@server1 ~]# mysqladmin -uroot -p password 'fa123'
[root@server1 ~]# mysql -uroot -p

Insert picture description here

Guess you like

Origin blog.csdn.net/F2001523/article/details/111658334