MySQL self-study (updating)

Basic knowledge of database

Why use a database

  1. Data is saved permanently
  2. Use SQL statements to easily query data

What is SQL?

Structured Query Language (Structured Query Language) is abbreviated as SQL, which is a database query language.

Role: used to access data, query, update and manage relational database systems.

What is MySQL

MySQL is a relational database management system developed by the Swedish company MySQL AB and is a product of Oracle. MySQL is one of the most popular relational database management systems. In terms of web applications, MySQL is one of the best RDBMS (Relational Database Management System) application software. It is very commonly used in Java enterprise-level development, because MySQL is open source, free, and easy to expand.

What are the three database paradigms

First paradigm: the columns cannot be divided

  1. Each column of attributes is an indivisible attribute value to ensure the atomicity of each column
  2. The attributes of the two columns are similar or similar or the same, try to merge the columns with the same attribute to ensure that no redundant data is generated

Second paradigm: attributes completely depend on the primary key

On the basis of the first normal form, each instance or row in the database table must be uniquely distinguishable. In order to realize the distinction, it is usually necessary to add a column to the table to store the unique identification of each instance. This unique attribute column is called the primary key

The third paradigm: attributes do not depend on other non-primary attributes, attributes directly depend on foreign keys

On the basis of the second paradigm, it is required that the data cannot have a transitive relationship, that is, each attribute has a direct relationship with the primary key rather than an indirect relationship. Such a relationship between attributes like: a–>b–>c does not conform to the third normal form.

For example, Student table (student number, name, age, gender, college, college address, college phone)

The school address and school phone field do not have a direct relationship with the primary key, but have a direct relationship with the school, so they do not meet the requirements of the third normal form.

to sum up

The three paradigms are basic database design concepts, but in actual production, demand and performance are more important.

MySQL permission table

The MySQL server controls the user's access to the database through the permission table. The permission table is stored in the mysql database and initialized by the mysql_install_db script. These permission tables are user, db, table_priv, columns_priv and host.

  • User permission table: record the user account information allowed to connect to the server, the permissions inside are global.
  • db permission table: record the operation permissions of each account on each database.
  • table_priv permission table: records the operation permissions at the data table level.
  • columns_priv permission table: record data column-level operation permissions.
  • procs_priv permission table: records the permissions related to stored procedures and stored functions.
  • proxies_priv permission table: proxy user permissions.

MySQL binlog

MySQL's binary log binlog can be said to be the most important log of MySQL. It records all DDL and DML statements (except for data query statements select, show, etc.), recorded in the form of events, and also contains the time consumed by statement execution. MySQL The binary log is transaction-safe. The main purpose of binlog is to copy and restore.

Two important usage scenarios for Binlog logs

  • MySQL master-slave replication: the master node saves the data change records to the binlog log -> reads the binlog log from the library and saves it to the relay log log in the server -> reads the relay log log from the library SQL thread to complete data synchronization
  • Data recovery: use the mysqlbinlog tool to recover data

Binlog log format

  • Statement

    Record the SQL every time the data is modified

    Advantages: There is no need to record the changes of each line, reducing the amount of binlog, saving IO, and improving performance.

    Disadvantages: Because SQL is recorded, in order to ensure consistent execution results of SQL, it is also necessary to record the context of SQL runtime. And some specific functions may not guarantee master-slave data synchronization

  • Row

    Do not record the SQL statement context, only save which record was modified

    Advantages: Binlog only records which piece of data has been modified, so it solves the problem of master-slave data synchronization in some specific situations

    Disadvantages: a large number of logs will be generated and take up space

  • Mixed

    Combination of Statement and Row

    General statements are recorded in the Statement method, and the SQL statements that cannot complete the master-slave replication operation are recorded in the Row method.

Reference blog

Involving infringement, please private message.

MySQL database interview questions (the latest version of 2020)

Three database paradigms

Introduction to MySQL Binlog

Guess you like

Origin blog.csdn.net/mabaohe110/article/details/115350008