Mysql related knowledge application 1: concept

Reference URL

Browse the catalog

  • Overview
  • Characteristics of the database
  • Classification of the database
  • Reasons to choose MySQL & Introduction to MariaDB
  • Download and install

I. Overview

1. Data

The information stored in the table is called data.

2. Database (DB for short)

The database is a warehouse for storing data. This warehouse is organized and stored according to a certain data structure (data structure refers to the organizational form of the data or the connection between the data). We can manage the database through various methods provided by the database Data. For a simpler image understanding, the database is the same in nature as the warehouse in which we store debris. The difference is that the stored things are different.

3. Database table

A data table is a very important object in a relational database, the basis of other objects, and a collection of two-dimensional arrays , used to store and manipulate the logical structure of data.
According to the classification of information.
A database may contain a plurality of data tables, each table is composed of rows and columns, a data record, the data table to add a line, and each column is a field names and data collection of the column is called a field,
each column There are also multiple attributes of their own, such as whether to allow null, default, length, type, storage encoding, comments, etc.

4. The database system has 3 main components

1). Database (Database System): used to store data.

2). Database management system (Database Management System, DBMS): software for users to manage the database.

3). Database Application (Database Application): Software supplement for the management database used to improve the processing capacity of the database system.

5. The history of database development (five stages)

1). File system
  The germination stage of the database system, access data through files. The
file system is the germination stage of the database system, appeared in the 1950s and 60s of the last century, can provide simple data access functions, but can not provide complete, Unified data management functions, such as complex queries. So in the case of less management, simpler data or just used to access simple data, without complicated operations, the file system will be used
   
2). Hierarchical database
  database system really started, the data storage form is similar to a tree structure , So it is also called tree database.
   
3). Mesh database The
  data storage form is similar to mesh structure.
Since the 1960s, the first generation of database systems (hierarchical model database system, mesh model database system) When they came out, they provided powerful support for unified management and shared data.
At this stage, the mesh model database was not widely used because of its complexity and specificity. In the hierarchical model database, IBM's IMS (Information Management System, Information Management System) hierarchical model database system has been greatly developed, once became the largest database management system, with a huge customer base

4). Relational database
In the early 1970s, relational database systems began to enter the historical stage and have maintained a vigorous vitality. Relational database systems use Structured Query Language (SQL) as the database Definition language DDL and database operation language DML

5). The object-oriented database (non-relational database)
combines object-oriented methods and database technology , which can make the analysis and design of the database system to the greatest extent consistent with people's understanding of the objective world, and can effectively face Object programs provide better database support

Second, the characteristics of the database

⑴ Realize data sharing
 Data sharing includes all users can access the data in the database at the same time, including users can use the database in various ways through the interface, and provide data sharing.
⑵ Reduce the redundancy of data
 Compared with the file system, because the database realizes data sharing, thus avoiding the user to establish application files. Reduced a lot of duplicate data, reduced data redundancy, and maintained data consistency.
(3) Data consistency and maintainability to ensure data security and reliability
 Mainly include: ①Security control: to prevent data loss, Error update and unauthorized use;
      ② Integrity control: to ensure the accuracy, validity and compatibility of data;
      ③ Concurrency control: to allow multiple access to data within the same time period, but also to prevent users from Abnormal interactions .
⑷ Failure recovery The
  database management system provides a set of methods to detect and repair failures in time to prevent data from being destroyed. The database system can recover the faults that occurred during the operation of the database system as soon as possible, which may be physical or logical errors. For example, data errors caused by misuse of the system.
Third, the classification of databases
In today's Internet, the most commonly used database models are mainly two, namely relational databases and non-relational databases.

1. Introduction to relational database

(1) Relational database: It is to reduce the complex data structure to a simple binary relationship (that is, a two-dimensional table format).

(2) Current mainstream relational databases: MySQL, Oracle, Sql server, DB2 . . .

Introduction to mainstream databases

2 Introduction to non-relational databases

(1) Birth background of non-relational database

Non-relational databases are also called NoSQL databases . The original meaning of NOSQL is "Not Only SQL". It does not mean "No SQL". Therefore, the generation of NoSQL is not to completely deny non-relational databases, but as a traditional relationship. An effective supplement to the type database. NOSQL database can exert unimaginable high efficiency and high performance in specific scenarios.

     随着互联网Web2.0网站的兴起,传统的关系型数据库在应付web2,0网站,特别是对于规模日益扩大的海量数据,超大规模和高并发的微博、微信、SNS类型的web2.0纯动态网站已经显得力不从心,暴露了很多难以克服的问题。 

For example, traditional relational database IO bottlenecks and performance bottlenecks are difficult to break through effectively, so a large number of database products with specific functions for high performance and convenience have appeared for specific scenarios. NOSQL (non-relational) data is born in this situation and has developed very rapidly

(2) Summary of NOSQL non-relational database:
  1. NOSQL is not a negative relational database, but an important supplement to the relational database
  2. NOSQL is born for high performance and high concurrency, but the requirements for data consistency cannot be high
  3. NOSQL typical products memcached ( pure memory, kv ), redis ( persistent cache, kv ), mongodb (document database, xml-json )

4. Reasons for choosing MySQL & MariaDB introduction

1. Reasons for choosing MySQL
MySQL has excellent performance, stable service, and there are few abnormal downtimes.
MySQL has open source code and no copyright restrictions. It has low autonomy and low cost.
MySQL has a long history, active community and users, and can solve
MySQL software if problems are encountered Small size, simple installation and use, and easy maintenance, low installation and maintenance cost
MySQL brand word of mouth effect, so that enterprises do not need to consider directly
support MySQL multi-use operating system, provide multiple API interfaces, support multi-use development language, especially for popular languages There is good support.
2. Introduction of MariaDB
appeared in 2009. The MAriaDB database management system is a branch of the MySQL database, which is mainly maintained by the open source community and is licensed under the GPL.
One of the reasons for the development of this MariaDB is that after Oracle acquired MySQL, MySQL has the potential risk of being closed source, so the MySQL open source community adopted a branch approach to avoid this risk. MariaDB's default storage engine is Maria, not MyISAM: additional note Mysql MyISAM engine does not support transactions . Maria can support transactions, but transaction support is not turned on by default, because transaction support has an impact on performance. You can use the following statement to convert to a Maria engine that supports transactions. TRANSACTIONAL is set to 1 to start the transaction
ALTER TABLE tablename ENGINE = MARIA TRANSACTIONAL = 1;

Five, download and installation

1. Overall download and installation steps: usually use Navicat and other visual tools to manage Mysql and other relational databases.
Official website download mysql installation program
Install mysql server
install mysql client
Client connection
server sends commands to the server through the client to execute the database file Add, delete, and change operations.
2. Windows installation (ZIP archive installation)
download: MySQL Community Server 5.7.20 download address
Decompression: extract the decompression package downloaded from the official website to a specified directory (for example, D: //mysql-5.7.20-winx64) and
add environment variables: Add the bin directory under the extracted folder to the system environment variables (for example: D: \ mysql-5.7.20-winx64 \ bin)
Initialization: Enter the command on the cmd command line: mysqld –initialize-insecure
Start the mysql service: in the cmd command Enter the command line: mysqld to
connect to the mysql service: In addition, open the cmd command line and enter: mysql -uroot -p Enter, enter the password with a password, and do not continue to enter. The
installation is successful. Next, manually create a Windows system service for MySQL (ps: The production service must use the full path method) to
make MySQL Windows service, enter this command in the cmd command line: "D: \ mysql-5.7.20-winx64 \ bin \ mysqld" -install
To remove the MySQL Windows service, enter this command on the cmd command line: "D: \ mysql-5.7.20-winx64 \ bin \ mysqld" --remove
start the MySQL service: enter on the cmd command line: net start mysql to
close the MySQL service: Enter in the cmd command line: net stop mysql
PS: completely uninstall mysql reference: reference URL
3, linux installation
download address: download address
can also be downloaded directly through the command: wget http://dev.mysql.com/get/Downloads/MySQL -5.7 / mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
unzip: tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
copy and decompress the mysql directory: cp -r mysql-5.7.11-linux-glibc2.5-x86_64 / usr / local / mysql
add user group and user: groupadd mysql
add user mysql to user group mysql: useradd -g mysql mysql
installation: cd / usr / local / mysql / mkdir ./data/mysql
chown -R mysql: mysql ./
./scripts/mysql_install_db –user = mysql –datadir = / usr / local / mysql / data / mysql
cp support-files / mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files / my-default.cnf /etc/my.cnf
modify the startup script: vi / etc / init.d / mysqld
modify items:
basedir = / usr / local / mysql /
datadir = / usr / local / mysql / data / mysql
start service: service mysqld start
test connection: ./mysql/bin/mysql -uroot
add environment variables , Edit / etc / profile, so that you can use the mysql command anywhere to
export PATH = $ PATH: / usr / local / mysql // bin
source / etc / profile
start mysql: service mysqld start
close mysql: service mysqld stop to
view the operation Status: service mysqld status
Some solutions to errors during installation:
Error 1: When sqlyog is connected, a 1130 error is reported because the user permission for the remote connection is not
resolved. 1: Change the 'host' entry in the 'mysql' database 'user' table , Change from 'localhost' to '%'
use mysql;
select 'host' from user where user = 'root';
update user set host = '%' where user = 'root';
flush privileges;
Solution 2: Direct authorization
GRANT ALL PRIVILEGES ON. TO 'root' @ '%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
Error 2: -bash: ./scripts/mysql_install_db: / usr / bin / perl: bad interpreter: No such file or directory
Solved: yum -y install perl perl-devel
Error 3: Installing MySQL system tables…. / bin / mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directorySolution
: yum -y install libaio-devel


Next article connection: Mysql related knowledge application 2: Mysql database engine (MyISAM, Innodb)

Published 27 original articles · praised 0 · visits 9934

Guess you like

Origin blog.csdn.net/weixin_38246518/article/details/89502318