MySQL database and installing MySQL

Article Directory

1. The basic concept of database

1. Data

(1) Symbolic records describing things

(2) Including numbers, text, graphics, images, sounds, file records, etc.

(3) Store in a unified format in the form of "records"

2. table

(1) Organize different records together

(2) Used to store specific data

3. Database

(1) A collection of tables is a warehouse for storing data

(2) A collection of relevant data stored in a certain organizational manner

4. Database Management System (DBMS)

(1) It is a system software that realizes the effective organization, management and access of database resources

(2) Database establishment and maintenance functions, data definition functions, data manipulation functions, database operation management functions, communication functions

4.1 DBMS mainly includes the following functions

(1) Database establishment and maintenance functions: including establishment of database structure, data entry and conversion, database dump and recovery, database reorganization and performance monitoring and other functions.

(2) Data definition function: including functions such as defining global data structure, local logical data structure, storage structure, security mode and information format. Guarantee that the data stored in the database is correct, valid and consistent, so as to prevent wrong data that does not conform to semantics from being input or output.

(3) Data manipulation function: including data query statistics and data update

(4) Operation and management function of the database: This is the core part of the database management system, including functions such as concurrency control, access control, and internal maintenance of the database.

(5) Communication function: Communication between DBMS and other software systems, such as Access can exchange data with other office components.

5. Principle of database system

(1) It is a man-machine system composed of hardware, OS, database, DBMS, application software and database (2) Users can operate the database through DBMS or application programs

(3) Work flow of the database

insert image description here

5.1 Working mode of DBMS

(1) Accept data requests from applications and process requests

(2) Convert user data requests (high-level instructions) into complex machine codes (bottom instructions)

(3) Realize the operation of the database
(4) Accept the query result from the operation of the database

(5) Process the query results (format conversion)

(6) Return the processing result to the user

two. The history of database development

1. The first generation database

(1) Since the 1960s, there have been

(2) It is a database system with hierarchical model and network model

(3) Provide strong support for unified management and data sharing

2. The second generation database

(1) In the early 1970s, the second-generation database-relational database began to appear

(2) In the early 1980s, IBM's relational database system DB2 came out and began to gradually replace the hierarchical and network model databases, becoming the mainstream of the industry

(3) So far, relational database systems still occupy the main position of database applications

3. The third generation database

(1) Since the 1980s, new database systems adapted to different fields have emerged continuously

(2) Object-oriented database system with strong practicability and wide adaptability

(3) In the late 1990s, a situation in which multiple database systems jointly supported applications was formed

(4) Some new elements are added to mainstream database systems

3.1 Characteristics of the third generation

Some new elements are added to the mainstream database system
Extension: SQL + NoSQL combined use of
web - redis - mysql
CPU - cache - memory

three. mainstream database

1.SQL Server (Microsoft product)

(1) Simple for Windows operating system

(2) Ease of use

2. Oracle (Oracle products)

(1) For all mainstream platforms

(2) Safe, perfect, and complicated to operate

(3) Two machines with high configuration requirements (above 128G) How to solve bugs and bugs: only open to the application, not to others, it is more secure to set a separate user password for the application.

3. DB2 (IBM product)

(1) For all mainstream platforms

(2) Large, safe and complete

4. MySQL (acquired by Oracle Corporation)

(1) Free, open source, small size

Four. Relational and non-relational databases

1. Relational Database

(1) A relational database system is a database system based on a relational model

(2) The data structure of the relational model uses an easy-to-understand two-dimensional data table

(3) The relational model can be represented by a simple "entity-relationship" (ER) diagram

(4) The ER diagram contains three elements: entity (data object), relationship and attribute

1.1 Relational database structure

1.1.2 Entity


(1) Also known as an instance, it corresponds to an "event" or "thing" that can be distinguished from other objects in the real world

(2) For example: such as bank customers, bank accounts

1.1.2 Properties

(1) A certain characteristic of an entity, an entity can have multiple attributes

(2) For example, each entity in the "bank customer" entity set has attributes such as name, address, and
phone number

1.1.3 Contact

(1) The corresponding relationship between entity sets is called connection, also known as relationship

(2) If there is a "savings" relationship between the bank customer and the bank account

Total: The collection of all entities and the connections between entities constitutes a relational database

1.2 Structure of relational database

(1) The storage structure of the relational database is a two-dimensional table

(2) In each two-dimensional table

  • Each row is called a record, which is used to describe the information of an object
  • Each column is called a field and is used to describe a property of the object

1.3 Relational database application

(1) Oracle, MySQL——12306 user information system
(2) SQLServer, Sybase——Taobao account system

(3) Informix, access——China Unicom mobile phone number information system

(4) DB2, FoxPRO - bank user account system

(5) PostgreSQL - website user information system

2. Introduction to non-relational databases

2.1 Non-relational database

(1) Non-relational database is also called NoSQL (Not Only SQL)

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

(3) Commonly used non-relational databases: RedismongoDB, etc.

2.2 Advantages of non-relational databases:

(1) The database can be read and written in high concurrency
(2) It can efficiently store and access massive data
(3) The database has high scalability and high availability

3. The difference between relational database and non-relational database

3.1 Relational database

(1) The relational database structure is a two-dimensional database table. Each field (column) in the two-dimensional table is used to describe an attribute of the object, and each record row) is used to describe the information (complete information) of an object. Where the relational database is written is the IO limitation or bottleneck that the reading and writing system will suffer when it is stored in the hard disk.

(2) The most typical data structure of a relational database is a table, a data organization composed of two-dimensional tables and their connections

3.1.1 Advantages of relational database

(1) Easy to maintain: all use the table structure with the same format;
(2) Easy to use: the SQL language is common and can be used for complex queries;
(3) Complex operations: support SQL, which can be used for very complex queries between one table and multiple tables.

3.1.2 Disadvantages of relational database

(1) The reading and writing performance is relatively poor, especially the high-efficiency reading and writing of massive data;
(2) The fixed table structure is slightly less flexible;
(3) The high concurrent reading and writing requirements, for traditional relational databases, hard disk I/O is a big bottleneck.

3.2 Non-relational database (NoSQL)

(1) MongoDB, Redis (memory database/cache database) KV key-value pair, similar Memcache, KV key-value pair
redis-memecache comparison:
the same point: store high-heat data (running at high speed in memory)
difference: redis can be used for persistent storage, and can store objects

(2) Strictly speaking, non-relational databases are not a kind of database, but should be a collection of data structured storage methods, which can be documents or key-value pairs.

3.2.1 Advantages of non-relational databases

(1) Flexible format: The format of stored data can be in the form of key, value, document, picture, etc. It is flexible to use and has a wide range of application scenarios, while relational databases only support basic types.
(2) Fast speed: nosql can use hard disk or random access memory as a carrier, while relational database can only use hard disk; (
3) high scalability;
(4) low cost: nosql database is easy to deploy and basically is open source software.

3.2.2 Disadvantages of non-relational databases

(1) Does not provide sql support, and the cost of learning and using is high;
(2) No transaction processing;
(3) The data structure is relatively complex, and the complex query is slightly lacking.
(4) A lot of data is written in memory

five. MySQL database introduction

1. MySQL database

(1) A popular open source relational database

(2) Oracle's products

(3) Comply with the GPL agreement, free to use and modify

2. MySQL database features

(1) Excellent performance and stable service

(2) Open source, no copyright restrictions, low cost

(3) Multi-thread, multi-user

(4) Based on C/S (client/server) architecture

(5) safe and reliable

3. MySQL Business Edition and Community Edition

(1) The commercial version of MySQL is charged. Developed and maintained by AB Company

(2) The MySQL Community Edition is free to use and is developed and maintained by MySQL developers and enthusiasts scattered around the world

(3) The difference between the two

  • The commercial version has stricter organizational management and testing links, 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, the community version does not

(4) Download URL http://www.devmysql.com/downloads

4. version evolution

MySQL: 5.1 --> 5.5 --> 5.6 --> 5.7 --> 8.0 (no 6.0, 7.0, etc.)

MariaDB: 5.1 --> 5.5 --> 10.0 --> 10.1 --> 10.2 --> 10.3 --> 10.4 --> 10.5 (from 5.1, skip to 10.0)

six. Compile and install MySQL

1. Install the Mysql environment dependency package

systemctl stop firewalld.service 
setenforce 0
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

2. Create a running user

#M不创建数据库的目录,s指定权限
useradd -M -s /sbin/nologin  mysql

3. Compile and install

Drag in the mysql-boost-5.7.20.tar.gz installation package

Unzip the installation package

cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
cd /opt/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_EXTRA_CHARSETS=all \
-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
make -j2 && make install

4. Modify the mysql configuration file

vim /etc/my.cnf
[client]
port = 3306
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
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

5. Change the owner and group of the mysql installation directory and configuration files

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

6. Set the path environment variable

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile	
source /etc/profile

7. Initialize the database

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

8. Add mysqld system service

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
netstat -antp | grep 3306

9. Modify the login password of mysql

mysqladmin -u root -p password "abc123"
回车

10. Authorize remote login

mysql -u root -p
#查看是否创建成功数据库
#输入数据库密码
Enter password:
mysql>show databases;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password';
mysql>FLUSH PRIVILEGES;
mysql>exit
Bye

insert image description here
insert image description here

total

1. Describe the mainstream database system

Relational database:
Mysql (Oracle), SQL server (Microsoft), access (Microsoft office products),
Oracle, DB2 (IBM), sybase (sybase), etc.

2. The process when the database management system DBMS client performs data acquisition

1> Accept application data requests and process requests

2> Convert user data requests (high-level instructions) into complex machine codes (low-level instructions)

3> Realize the operation of the database

4> Accept the query result from the operation of the database

5> Process the query results (format conversion)

6> Return the processing result to the user

3. The difference between relational database and non-relational database

Relational databases process data

Non-relational databases are data stored in cached relational databases in memory (do not process data)

4.mysql database log

4.1 Function:

Database log files are used for backup, recovery, fault location and analysis is the core part

4.2 The difference between mysql and oracle logs

mysql writes a piece of data and synchronizes it to a log in a
PS:insert into qqbb (id,name,score) values(1,'zhangsan',20);
oracle: Redo log group
There are at least 3 log members in a group, and the log is stored in turn, and
there will be another group to synchronize/backup with it

4.3 Mysql storage engine

myisam and innodb
myisam: fast read, does not support transactions (frm, myd, myi)
innodb: pays more attention to writing, supports transactions (ibd.frm)

Guess you like

Origin blog.csdn.net/Katie_ff/article/details/131640949