1. Database base (focus)
1.1 What is a database
Storing data files on it, why get hold of a database?
Save the data file has the following disadvantages:
-
Document security issues
-
File is not conducive to data query and management
-
File is not conducive to store massive amounts of data in a convenient file control program
Database storage media:
-
Disk
-
RAM
To solve this problem, the experts to design more things conducive to the management of data - databases, it can more effectively manage data. Level database is an important indicator of the level of a programmer.
1.2 mainstream database
-
SQL Sever: Microsoft's products, .Net programmer's favorite, in large-scale projects.
-
Oracle: Oracle products for large-scale projects, complex business logic, concurrent generally not as good as MySQL.
-
MySQL: the world's most popular database, is Oracle, concurrency is good, is not suitable for complex business. Mainly used in the electric business, SNS, forum. Good for simple SQL processing effects.
-
PostgreSQL: University of California relational database computer system developed at Berkeley, whether private, commercial, academic or research use,
with free use, modify and distribute. -
SQLite: database is a lightweight, ACID-compliance is a relational database management system, which is contained in a relatively small C library. Its design goal is embedded, and has now used it in many embedded products, it takes resources are very low in embedded devices, may only need a few hundred K of memory is enough.
H2: is a development with Java embedded database, which itself is just a class library that can be embedded directly into your application.
1.3 Basic use
1.3.1 MySQL Installation
1.3.2 connection to the server
Input:
mysql -h 127.0.0.1 -P 3306 -u root -p
Output:
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
note:
If you do not write -h 127.0.0.1 default is the local connection
If you do not write -P 3306 is the default port number 3306 connection
1.3.3 Server Management
-
Execution win + r enter services.msc to open the Services Manager
-
Through the left side next stop, pause, reset button service management
1.3.4 server, database, table relationships
-
The so-called install the database server on the machine just installed a database management system program, the hypervisor can manage multiple data
repository, usually a developer will create a database for each application. -
To save the data in the application entity, usually creates multiple tables in the database to hold the data the program entity. Relational database server, database and table are as follows:
1.3.5 Use Case
Create a database
create database helloworld;
Use Database
use helloworld;
Create a database table
create table student( id int,
name varchar(32), gender varchar(2)
);
Insert the data
insert into student (id, name, gender) values (1, '张三', '男'); insert into student (id, name, gender) values (2, '李四', '女'); insert into student (id, name, gender) values (3, '王五', '男');
Data look-up table
select * from student;
1.3.6 Data logical storage
1.4 MySQL architecture
MySQL is a database portable, it can run on almost all current operating systems, such as Unix / Linux, Windows, Mac, and Solaris. Various systems vary in terms of the underlying implementation, but ensures consistency substantially MySQL physical architecture on the respective platforms.
1.5 SQL classification
DDL data definition language, storing a data structure used to maintain
Representing instructions: create, drop, alter
DML data manipulation language, used to manipulate data
Representing instructions: insert, delete, update
DML, also scored a single DQL, data query language, representing the instructions: select
DCL Data Control Language, is responsible for rights management and transaction
Representing instructions: grant, revoke, commit
1.6 Storage Engine
1.6.1 Storage Engine
Storage engine is: how to store data in a database management system, how to create an index for the data storage and how to update, query data and other implementation technologies.
MySQL's core is the pluggable storage engine that supports multiple storage engines.
1.6.2 View Storage Engine
show engines;
Comparison 1.6.3 Storage Engine