The first time for MySQL (database concept, comparison of current mainstream databases and compiling and installing mysql)

Preface

  • Database (database), in short, can be regarded as an electronic file cabinet-a place for storing electronic files. Users can perform operations such as adding, intercepting, updating, and deleting data in the file.

  • The so-called "database" is a data collection that is stored together in a certain way, can be shared by multiple users, has as little redundancy as possible, and is independent of the application.

  • A database is composed of multiple tablespaces (tablespace)

  • Compared with notepads and documents, databases are large amounts of data, easy to manage data, easy to query data quickly, data algorithms, and unstructured characteristics

One: database overview

1.1: What is a database

1.1.1: Basic concepts

  • data
    • Symbol records describing things are called data (Data)
    • Including numbers, text, graphics, images, sounds, file records, etc.
    • Store in a unified format in the form of "records"
    • Each row, called a record
    • Each column, called a field
  • table
    • The different records are organized together to form a "table
    • Is used to store specific data
  • database
    • A database is a collection of tables and a warehouse for storing data
    • Interrelated data stored in a certain organization
  • Database Management System (DBMS)

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

  • 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

1.1.2: What is the role of the database?

  • Persistent storage of data
  • High reliability, high availability
  • Fast extraction of data

1.2: History of database system development

  • First generation database
    • Since the 1960s, the first generation of database systems came out. They are database systems of hierarchical model and network model, which provide strong support for unified management and sharing of data
  • 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. As the second-generation relational database of the database system, it began to gradually replace the database of the hierarchical and mesh model, becoming the dominant database and becoming the mainstream of the industry.
    • So far, relational database systems still occupy the main position of database applications
  • Third-generation database
    • Since the 1980s, various new database systems adapted to different fields have emerged, such as engineering databases, multimedia databases, graph databases, intelligent databases, distributed databases and object-oriented databases, etc., especially object-oriented database systems. Strong practicality, wide adaptability and favored by people
    • In the late 1990s, a situation in which multiple database systems jointly supported applications was formed
    • Of course, in terms of business applications, relational databases still dominate. However, some new elements have been added to mainstream business database systems.
    • For example, the "relation-object" database model supported by Oracle

1.3: Today's mainstream database types

1.3.1: Database storage type

  • Relational Database:
    • Stored are numeric values, characters, strings, Boolean values, etc.
  • Non-relational database:
    • What is stored is pictures, videos, voices, etc. (objects)

1.3.2: Relational Database

  • MySQL (acquired by Oracle)
    • Free, open source, small size
  • sql server (Microsoft product)
    • For Windows operating system
    • Simple and easy to use
  • access (Microsoft product)
    • For Windows operating system
    • Be a member of the Microsoft office suite application
  • oracle (Oracle company product)
    • For all major platforms
    • Safe, perfect, complicated operation
  • db2 (IBM Corporation)
    • For all major platforms
    • Large, safe and complete
  • sybase (Sybase company)
    • For all major platforms
    • Large, safe and complete
    • The world's largest

1.3.3: Non-relational database

  • MongoDB
  • Redis (memory/cache database), exists in the form of KV (key-value—) key-value pairs, variable name-value
  • memcache (memory/cache database), exists in the form of KV (key-value—) key-value pairs, variable name-value
  • Redis and memcache are similar
    • Store the high-heat database
  • Differences between Redis and memcache
    • Redis can do persistent preservation and can store objects

1.4: Detailed explanation of relational database

  • Relational database system is a database system based on relational model, and its basic concept comes from relational model
  • The relational model is based on the theory of relational algebra, and the data structure uses a simple and easy-to-understand two-dimensional data table, which can be directly represented by a simple "entity-relationship" (ER) diagram
  • The ER diagram contains three elements: entity (data object), relationship and attribute. E.g:

Insert picture description here

  • entity:
    • Also called an instance, it corresponds to "events" or "
      things" that can be distinguished from other objects in the real world , such as bank customers, bank accounts, etc.
  • Attributes:
    • For 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 phone number
  • contact:
    • Correspondence between entity sets is called association, also known as 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
  • There will be codes in relational database tables, called primary keys, which have unique and non-empty characteristics
  • The storage structure of the relational database is a two-dimensional table, and the data reflecting things and their connections are stored in the form of a 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
  • Application examples of relational databases:
    • 12306 User Information System
    • Taobao account information system, Alipay account system mobile, telecommunications, China Unicom mobile phone number information system, billing system bank user account system
    • Website User Information System

1.5: Detailed explanation of non-relational databases

  • Non-relational database is also called NOsQL (Not Only SQL)

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

  • As a supplement to the relational database, non-relational databases play high efficiency and high performance in the era of increasingly rapid development of websites

  • Advantages of non-relational databases

    • Database high concurrent read and write requirements
    • Efficient storage and access to massive data
    • High scalability and high availability requirements of the database
  • NoSQL mostly exists in the form of files

  • Relational database storage

    • Key-value method (key-value), store, delete, and modify data based on the key
    • Column storage (Column-oriented), store related data in column families
    • In the form of documents, the database consists of a series of data items, each of which has a name and a corresponding value
    • Graphic mode, entity is vertex, relationship is edge, data is saved as a graph
  • Non-relational database products

    • Memcached is an open source, high-performance cache system with distributed memory objects, which stores data in a key-value manner

      • Cache data to reduce database pressure and speed up access
      • Accelerate dynamic web applications
      • The cached content is kept in memory
    • Redis is also a way of storing data in a key-vaue manner. The data is also stored in the memory, but the data is periodically written to the disk.

      • Compared with Memcached, it has the following characteristics
        • Support memory cache
        • Support persistence
        • More data types
        • Support cluster, distributed
        • Support queue
    • The log file of the database is used for recovery, and the oracle log is called the redo log group

    • E.g:

      • Ali oss object storage adopts the idea of ​​oracle redo log group,

        Ali oss data is in triplicate, it is the Pangu system

        Redis has a relay log (binary log)

    • Redis application examples

      • Database front-end cache
      • session sharing
      • When more data types other than key/value need to be cached
      • When the cached data needs to be stored for a long time

Two: compile and install MySQL

2.1: MySQL database

2.1.1: The concept of MySQL database

  • MySQL is a popular Kaiyuan relational database
  • Oracle's products
  • Comply with the GPL agreement, free to use and modify
  • Features
    • Excellent performance and stable service
    • Open source, no copyright restrictions, low cost
    • Multi-threaded, multi-user
    • Give C/S (client/server) architecture
    • Safe and reliable

2.1.2: The difference between 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 test links, and better stability
    • The commercial version does not comply with GPL
    • The commercial version can get 7*24 hours of service, such as fault maintenance and patching, etc.

2.1.3: MySQL product camp

  • The first camp: 5.0-5.1, which can be said to be a continuation of early products
  • The second camp: 5.4-5.7 camp, better integration of 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 the new era of clusters for databases

2.2: Compile and install MySQL (version 5.7)

2.2.1: Install mysql environment dependency package

[root@localhost ~]# cd /opt
[root@localhost ~]# mkdir /mysql
[root@localhost ~]# cd /mysql
[root@localhost mysql]# yum -y install gcc \
gcc-c++ \
ncurses \				'字符终端的包,方便终端操作'
ncurses-devel \			
bison \					'函数库'
cmake					'跨平台的安装工具'

2.2.2: Compile and install

[root@localhost mysql]# cd /opt/mysql-5.7.20/			'boost是5.7版本的特性'
[root@localhost mysql-5.7.20]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \			'sock;通讯文件,连接数据库,通讯协议的载体'
-DSYSCONFDIR=/etc \										'配置目录指向etc'
-DSYSTEMD_PID_DIR=/usr/local/mysql \			'pid文件位置'
-DDEFAULT_CHARSET=utf8 \									'此行和下一行为字符集相关'
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \			'此行和下三行为存储引擎'
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \			'指定存放位置'
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1									'守护进程'
[root@localhost mysql-5.7.20]# make && make install

2.2.3: Create a user, set the permissions of the /usr/local/mysql directory

[root@localhost local]# useradd -s /usr/sbin/nologin mysql
[root@localhost local]# chown -R mysql.mysql mysql/

2.2.4: Edit the configuration file

[root@localhost local]# cd /etc
[root@localhost etc]# vim 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

2.2.5: Set environment variables

[root@localhost etc]# vim /etc/profile
'最后一行插入'
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@localhost etc]# source /etc/profile

2.2.6: Initialize the database

[root@localhost etc]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data 

2.2.7: Set mysql password and try to log in to the database

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
[root@localhost mysql]# netstat -ntap | grep 3306
[root@localhost mysql]# systemctl start mysqld.service 
[root@localhost mysql]# netstat -ntap | grep 3306
[root@localhost mysql]# systemctl enable mysqld.service 
[root@localhost mysql]# mysqladmin -u root -p password "ab123" 
Enter password:              '这里密码为空'
[root@localhost mysql]# mysql -u root -p
Enter password:              '这里密码为ab123'
mysql> show databases;
mysql> quit

Guess you like

Origin blog.csdn.net/m0_47219942/article/details/108024789