This MySQL study note inside Ant Financial is on fire, and the full version is released for the first time!

foreword

We visit various websites and APPs every day, such as WeChat, QQ, Douyin, Toutiao, etc. There are a lot of information and data on these websites, and these information and data need to be stored somewhere. Where are these data generally stored?

Usually these data are stored in the database. So if we need to develop a website or app, database is a technology we must master. Commonly used databases include mysql, oracle, sqlserver, db2, etc. Among the databases introduced above, oracle ranks first in terms of performance, and the service is quite good, but the charges are also very high. Financial companies have relatively high requirements for database stability, and generally choose oracle. mysql is free, and the others are temporarily charged. Mysql is also ranked first in the usage rate of Internet companies. The information is also very complete, and the community is also very active, so we mainly learn mysql.

Common concepts of database

DB: database, a container for storing data.

DBMS: Database management system, also known as database software or database product, is used to create or manage DB.

SQL: Structured Query Language, a language used to communicate with databases, is not owned by a certain database software, but is a common language for almost all mainstream database software. Chinese people need to speak Chinese to communicate with Americans, English needs to be communicated with Americans, and SQL language is required to communicate with databases.

Some characteristics of database storage data

  • Data is stored in tables, and tables are stored in databases

  • There can be multiple tables in a library, and each table has a unique name (table name) to identify itself

  • There are one or more columns in a table, and columns are also called "fields", which are equivalent to "attributes" in java

  • Each row of data in the table is equivalent to the "object" in java

Some suggestions for data type selection

(1) Choose the small but not the large: In general, choose the smallest data type that can store data correctly. Smaller data types are usually faster and occupy less disk, memory, and CPU cache.

(2) Simple is good: operations on simple data types usually require fewer CPU cycles. For example, operations on integers are much cheaper than operations on characters, because character sets and collation rules (collation rules) make characters more expensive than integers. more complex.

(3) Avoid NULL as much as possible: set the column as NOT NULL as much as possible, unless you really need a value of NULL type. Column values ​​with NULL will make indexing, index statistics, and value comparison more complicated.

(4) It is recommended to choose decimal for the floating-point type

(5) It is recommended to use the int or bigint type to record the time, and convert the time to a timestamp format, such as converting the time to seconds and milliseconds, and store it for easy indexing

How MySQL Privileges Work

How does mysql identify a user?

For security reasons, mysql uses the host name + user name to determine the identity of a user, because it is difficult to determine the identity of a user through the user name on the Internet, but we can use the ip Or the host name judges a machine, and a user who comes through this machine can be identified as a user, so mysql uses the user name + host name to identify the user's identity. When a user sends a command to mysql, mysql determines the user's authority through the user name and source (host).

Mysql permission verification is divided into two stages:

(1) Phase 1: Connect to the database. At this time, mysql will judge whether you have permission to connect according to your user name and your source (ip or host name)

(2) Phase 2: Initiate request operations to the mysql server, such as create table, select, delete, update, create index, etc. At this time, mysql will judge whether you have permission to operate these commands

How to use indexes correctly?

Learning index is mainly to write faster sql. When we write sql, we need to know why sql is indexed? Why do some sql not index? SQL will access those indexes, why is it so? We need to understand its principle and internal specific process, so that it can be used more smoothly and more efficient SQL can be written.

Indexes in Mysql are divided into clustered indexes (primary key indexes) and non-clustered indexes

Clustered index (primary key index)

Each table must have a clustered index. The data of the entire table is stored in the file in the form of a b+ tree. The key in the leaf node of the b+ tree is the primary key value, and data is the information of the complete record; Nodes store the value of the primary key.

To retrieve data through the clustered index, you only need to follow the b+ tree search process to retrieve the corresponding records.

nonclustered index

Each table can have multiple non-clustered indexes, b+ tree structure, the key of the leaf node is the value of the index field field, and data is the value of the primary key; non-leaf nodes only store the value of the index field.

When retrieving records through a non-clustered index, two operations are required. First, the primary key is retrieved from the non-clustered index, and then the record corresponding to the primary key is retrieved from the clustered index. This process requires one more operation than the clustered index.

The compiled MySQL study notes are very comprehensive and detailed, covering all aspects of MySQL basic learning, very suitable for beginners to get started!

The materials are also organized by category, with more specific content under each chapter:

This MySQL study note has a total of 578 pages, and now I will share it with everyone

Pay attention to the public account: programmer chasing the wind, reply 012 to get this MySQL study note for free,

Summarize

Learning is a lifetime thing. After studying for a period of time, if you want to check the learning effect, the best way is to summarize it yourself. For example, when I am studying, I will take notes by myself, and then summarize by myself. The notes I make can also facilitate subsequent review, and they are all my own understanding.

Guess you like

Origin blog.csdn.net/Design407/article/details/110654086