MYSQL Database --- Cognition and installation of Mysql database

[Knowledge of the database]

  • The database has the following characteristics:
    1. A large amount of data information can be stored in a structured manner to facilitate effective retrieval and access by users. 2. It can effectively maintain the consistency and integrity of data information and reduce data redundancy.
    3. It can meet application sharing and security requirements.

  • Database classification: relational database and non-relational database

  • Relational databases:
    a relational database system is based on a relational model database system
    2, the data structure of the relational model of the two-dimensional data using straightforward table
    3, using a simple relational model "Entity - Relationship" (the ER) is represented in FIG.
    4 , ER diagram contains three elements: entity (data object), relationship and attribute
    Insert picture description here

Entities: also called instances, corresponding to "events" or things that can be distinguished from other objects in the real world (such as bank customers, bank accounts, etc.)

Attribute: 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)

Connection: The corresponding relationship between entity sets is called connection, 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

  • Non-relational database
    1. Non-relational database is also called NOSQL (Not Only SQL)
    2. The storage book library is not based on the relational model and does not require a fixed table format.
    3. The advantages of non-relational databases. The
    database can read and write
    with high concurrency to massive data Efficient storage and access The
    database has efficient scalability and high availability
    4. Commonly used non-relational databases: Redis, mongoDB, etc.

  • MYSQL database
    1. A popular open source relational database
    2. Oracle's products
    3. Comply with the GPL agreement and can be used and modified for free
    4. Features
    excellent performance, stable service
    Open source, no version rights, low cost
    , multithreading, Multi-user
    based on C/S (client/server) architecture,
    safe and reliable

This is also the reason why the MYSQL database is used more frequently.

[The following will introduce how to install MYSQL database]

The Mysql database will be installed in the form of a decompressed package, and the installation demonstration will be performed on the virtual machine

[Install Mysql database]
1. Upload the software package mysql-boost-5.7.20.tar.gz to the /root directory
Insert picture description here

2. Installation environment

[root@localhost ~]# yum -y install gcc gcc-c++ make        #####安装编译语言

Insert picture description here

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

Insert picture description here
Insert picture description here
The installation is complete!

3. Create a user to run the mysql program

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

Insert picture description here
4. Compile and install

[root@localhost ~]# tar xzvf mysql-boost-5.7.20.tar.gz
[root@localhost ~]# cd mysql-5.7.20/
[root@localhost mysql-5.7.20]#

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-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

Insert picture description here

[root@localhost mysql-5.7.20]# make -j3         ####-j3就是使用三核进行编译,加载速度会快些。

Insert picture description here
(wait…)

[root@localhost mysql-5.7.20]# make install

Quick for a while, it's over in a while
Insert picture description here
Compilation is complete

5. Adjust the permissions of the database directory

[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/

Insert picture description here

6. Modify the configuration file

[root@localhost mysql-5.7.20]# 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

Insert picture description here
7. Change the owner and group of the /etc/my.cnf configuration file

[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf

Insert picture description here
8. Set environment variables

[root@localhost mysql-5.7.20]# echo'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# source /etc/profile

Insert picture description here
Insert picture description here
Insert picture description here
9. Initialize the database (fixed format)

[root@localhost mysql-5.7.20]# cd /usr/local/mysql/

Insert picture description here

[root@localhost mysql]#

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

Insert picture description here

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

Insert picture description here
10. The database is open, self-starting, and closed

[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl enable mysqld
[root@localhost mysql]# systemctl status mysqld

Insert picture description here

11. Filter the port to verify whether Mysql is open

[root@localhost mysql]# netstat -anpt | grep 3306

Insert picture description here
12. Set MYSQL password

[root@localhost mysql]# mysqladmin -u root -p password

Insert picture description here

13. Enter Mysql and the installation is complete.

[root@localhost mysql]# mysql -u root -p

Insert picture description here

———————————————————————————————————

That's it, thanks for watching

Guess you like

Origin blog.csdn.net/XCsuperman/article/details/108562660