Introduction and detailed MySQL database

The basic idea of ​​the database

data

  • Symbol data recording is referred to describe things (Data)
  • Including numbers, text, graphics, images, sound, archival records, etc.
  • According to a unified format for storage of a "record" form

table

  • Different records organized together to form a "table"
  • It is used to store data specific

database

  • Is a collection of database tables, data is stored in a warehouse
  • Data relating to each other in a certain way organizations store

History of database systems development

The first generation of database

  • Since the 1960s, the first generation of database systems available. They are hierarchical model database system and network model, providing strong support for unified management and data sharing

The second generation database

  • The early 1970s, the second generation database - a relational database began
  • The early 1980s, IBM's DB2 relational database systems available, as the second generation of database relational database system, began to gradually replace the database level and network model, became the dominant database, the mainstream industry. So far, relational database systems still occupied a major position database applications

Third-generation database

  • Since the 1980s, a variety of different database systems to adapt to new emerging fields, such as engineering databases, multimedia databases, graph databases, intelligent databases, distributed databases and object-oriented databases, object-oriented database system in particular, because of its practical, wide adaptation and people of all ages
  • 20 In the late 1990s, formed a variety of database systems support common application situation. Of course, in business applications, relational database is still the mainstream, but there are already some new elements are added into the mainstream business database system. For example, Oracle support "relationship - Object" database model

Today's mainstream database Introduction

SQL Server (Microsoft products)

  • For Windows operating system
  • Simple, easy to use

Oracle (Oracle Products)

  • For all major platforms
  • Security, improve, operate complex

DB2 (IBM Corp.)

  • For all major platforms
  • Large, safe, sound

MySQL (Oracle acquisition)

  • Free, open source, small size

relational database

  • Relational database system is a database system based on the relational model, its basic concepts from the relational model
  • Relationship model based on the theory of the relational algebra, data structures using straightforward two-dimensional data table, you can use a simple "entity - relationship" plans to direct representation
  • FIG ER contains the following entities (data objects), the relationship between the three elements and attributes

Introduction and detailed MySQL database

entity

  • Also called instance, the corresponding real-world objects can be distinguished from other "events" or "things", such as bank customers, bank accounts, etc.

Attributes

  • Entity having a certain characteristic, an entity may have multiple attributes. For example, "bank customer" Each entity has a centralized entity name, address, telephone and other property

contact

  • Correspondence between the entity set called contact, also called relations. For example, there is a relationship between the "savings" between bank customers and bank accounts

The set of all links between entities and entity constitutes a relational database

Storage structure is two-dimensional relational database tables, reflect things and their contact data is saved in table form

In each two-dimensional table, each line is called a record, the information used to describe an object; each column is called a field, is used to describe a property of the object

Relational database applications

Relational Database

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

Relational Database Application examples

  • 12306 User Information System
  • Taobao account information system, Alipay account system, Mobile, Telecom, China Unicom mobile phone signal information system, billing system user account banking system
  • Web site user information system

Non-relational database introduces

  • Also referred to as non-relational databases NoSQL (Not Only SQL), data is not stored in the relational model is based, does not require a fixed table form
  • Non-relational database as a complementary relational database, in the increasingly rapid development of the Internet age, playing a high-efficiency and high performance
  • The advantages of non-relational databases
    • Demand for high concurrent read-write database
    • Efficient mass data storage and access to
    • High scalability and high availability requirements for the database

Non-relational database storage

  • Key - the value of mode (key-value), the key is to store, delete, change data basis
  • Storage column (Column-oriented), the relevant data is stored in the column family
  • How the document, the database consists of a series of data items, each data item has a name and a value corresponding to
  • Graphically entity as a vertex, edge relationship, save data to a graphic

Non-relational database products

  • Memcached is an open source, high-performance, distributed memory object caching system to store data in key-value

    • Cache data in order to reduce stress and to speed up database access speed
    • Accelerate dynamic Web applications
    • Cached content stored in memory
  • redis is also a way to store key-value data, the data is stored in memory, but will regularly write data to disk
  • It has the following characteristics relative to FMemcached
    • Support memory cache
    • Support persistence.
    • More Data Types
    • Support for clusters, distributed
    • Support queue

Application examples redis

  • Database front-end cache
  • sharing session
  • When the need to buffer more data types in addition to the key / value of
  • When a cache of data need long-term preservation

MySQL database Introduction

  • MySQL is a popular open source relational database
  • Oracle's products
  • Compliance with the GPL, can be used to modify free
  • Feature
    • Performance, service stability
    • Open source, copyright-free, low cost
    • Multi-threaded, multi-user
    • Based on C / S (Client / Server) architecture
    • Safe and reliable

MySQL Community Edition and Business Edition

  • MySQL commercial version is responsible for the development and maintenance of MySQL AB, to pay to use
  • MySQL Community Edition is a MySQL developers scattered around the world, the development and maintenance of lovers together, free to use
  • Difference between the two
    • Business Edition Management and more rigorous test session, better stability
    • Business Edition does not comply with GPL
    • Commercial version available 7 * 24-hour service, such as failure to maintain and patching, etc.

MySQL product portfolio

  • The first camp: 5.0-5.1 camp, it can be said to be a continuation of earlier products
  • The second camp: 5.4-5.7 camp, to better integrate the MySQL AB company, the community, the company opened a third party storage engine, which improves performance
  • The third camp: 6.0-7.1 camp is MySQL Cluster version, to meet the needs of the new era of clustered database developed
  • MySQL download site

MySQL installations

  • Open the VMware virtual machine Linux system, and download the compressed package to host MySQL, and MySQL settings are saved archive folder sharing, easy to use Linux systems to mount MySQL5.7 download
[root@localhost ~]# yum install gcc gcc-c++ make ncurses ncurses-devel bison cmake -y    //安装环境包
已加载插件:fastestmirror, langpacks
base                                                               | 3.6 kB  00:00:00     
extras                                                             | 2.9 kB  00:00:00
...
已安装:
  bison.x86_64 0:3.0.4-2.el7                          cmake.x86_64 0:2.8.12.2-2.el7       
  gcc.x86_64 0:4.8.5-39.el7                           gcc-c++.x86_64 0:4.8.5-39.el7       
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4       

作为依赖被安装:
  cpp.x86_64 0:4.8.5-39.el7               glibc-devel.x86_64 0:2.17-292.el7              
  glibc-headers.x86_64 0:2.17-292.el7     kernel-headers.x86_64 0:3.10.0-1062.4.3.el7    
  libmpc.x86_64 0:1.0.1-3.el7             libstdc++-devel.x86_64 0:4.8.5-39.el7          
  m4.x86_64 0:1.4.16-10.el7              

更新完毕:
  make.x86_64 1:3.82-24.el7             ncurses.x86_64 0:5.9-14.20130511.el7_4            

作为依赖被升级:
  glibc.x86_64 0:2.17-292.el7                 glibc-common.x86_64 0:2.17-292.el7         
  libgcc.x86_64 0:4.8.5-39.el7                libgomp.x86_64 0:4.8.5-39.el7              
  libstdc++.x86_64 0:4.8.5-39.el7             ncurses-base.noarch 0:5.9-14.20130511.el7_4
  ncurses-libs.x86_64 0:5.9-14.20130511.el7_4

完毕!
[root@localhost ~]# useradd -s /sbin/nologin mysql     //创建MySQL程序型用户
[root@localhost ~]# mount.cifs //192.168.100.8/shares /mnt/       //将宿主机中MySQL压缩包路径挂载到Linux系统中
Password for root@//192.168.100.8/shares:  
[root@localhost ~]# cd /mnt/     //进入挂载点目录
[root@localhost mnt]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt      //解压MySQL压缩包到opt目录
......
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/detail/extract_key.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/detail/buckets.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/detail/allocate.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/detail/util.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/unordered_map.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/unordered_set.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/unordered_set_fwd.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/unordered/unordered_map_fwd.hpp
mysql-5.7.20/boost/boost_1_59_0/boost/timer.hpp
[root@localhost mnt]# cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]# cmake \        //配置mysql
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \        //指定安装路径
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \  //指定mysql.sock.路径
> -DSYSCONFDIR=/etc \                               //指定配置文件存放位置
> -DSYSTEMD_PID_DIR=/usr/local/mysql \             //指定pid文件存放为位置
> -DDEFAULT_CHARSET=utf8 \                         //字符集格式utf-8
> -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 \                          //关联支持c++运行库
> -DWITH_SYSTEMD=1                            //开启systemd
....
-- CMAKE_C_LINK_FLAGS: 
-- CMAKE_CXX_LINK_FLAGS: 
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/mysql-5.7.20
[root@localhost mysql-5.7.20]# make                       //make过程(时间比较长,耐心等待)
....
[100%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o
Linking CXX executable mysql_embedded
[100%] Built target mysql_embedded
Scanning dependencies of target mysqltest_embedded
[100%] Building CXX object libmysqld/examples/CMakeFiles/mysqltest_embedded.dir/__/__/client/mysqltest.cc.o
Linking CXX executable mysqltest_embedded
[100%] Built target mysqltest_embedded
Scanning dependencies of target my_safe_process
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process
[root@localhost mysql-5.7.20]# make install     //安装
...
-- Installing: /usr/local/mysql/./COPYING-test
-- Installing: /usr/local/mysql/./README-test
-- Up-to-date: /usr/local/mysql/mysql-test/mtr
-- Up-to-date: /usr/local/mysql/mysql-test/mysql-test-run
-- Installing: /usr/local/mysql/mysql-test/lib/My/SafeProcess/my_safe_process
-- Up-to-date: /usr/local/mysql/mysql-test/lib/My/SafeProcess/my_safe_process
-- Installing: /usr/local/mysql/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /usr/local/mysql/support-files/mysqld_multi.server
-- Installing: /usr/local/mysql/support-files/mysql-log-rotate
-- Installing: /usr/local/mysql/support-files/magic
-- Installing: /usr/local/mysql/share/aclocal/mysql.m4
-- Installing: /usr/local/mysql/support-files/mysql.server
[root@localhost mysql-5.7.20]# cd /usr/local/           //进入安装目录
[root@localhost local]# chown -R mysql.mysql mysql/     //mysql目录更改用户与组
[root@localhost local]# mv /etc/my.cnf /etc/my.cnf.bak     //更改配置文件名称
[root@localhost local]# vim /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
:wq
[root@localhost local]# vim /etc/profile
...
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH     
export PATH                                //重新声明环境变量
:wq
[root@localhost local]# source /etc/profile      //重新执行
[root@localhost local]# cd /usr/local/mysql/bin          //进入MySQL命令目录
[root@localhost bin]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data                  //初始化数据库
2019-12-02T11:51:28.112082Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-02T11:51:28.263398Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-02T11:51:28.287408Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-02T11:51:28.341284Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 131f32df-14fa-11ea-87e6-000c297265cb.
2019-12-02T11:51:28.342106Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-12-02T11:51:28.342452Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@localhost ~]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service  /lib/systemd/system/ 
//将MySQL启动脚本夫复制到系统system目录下
[root@localhost ~]# systemctl enable mysqld.service      //设置MySQL为开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl start mysqld.service          //启动MySQL
[root@localhost ~]# mysqladmin -u root -p password     //设置MySQL数据库密码
Enter password:                  //没有原始密码,直接回车
New password:                   //输入新密码
Confirm new password:           //再次输入密码
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.  
//安全提示
[root@localhost ~]# mysql -u root -p      //登录MySQL
Enter password:          输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;     //查看数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Guess you like

Origin blog.51cto.com/14473285/2455483