Day128: MySQL advanced:

itread01 2021-01-22 01:17:09
day128 day mysql advanced


Catalog

1. Introduce and install

2. Basic management

2.1 User management

2.2 License management

2.3 Connection management

2.4 Configuration Management

3.MySQL The architecture of

4.SQL

5. Index and execution plan

1. Introduce and install

1.1 Database classification

RDBMS( Relational databases ):Relational Database Management System

On behalf of the product :Oracle  MySQL  MSSQL PG 

NoSQL( Non relational database ):Not Only SQL

Representative works :MongoDB  Redis  ES

NewSQL( For all kinds of new extensible packages / Short for high performance database )

Representative works :spanner  PolarDB(X)  TDSQL  TiDB  gaussian

1.2 MySQL Branch

1.Oracle

2.Percona

3.MariaDB

4. Cloud vendors

1.3 MySQL Get

www.mysql.com

1.4 MySQL Install

# 1. Unloading [[email protected] opt]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz# 2. Soft link ln -s /opt/mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql # 3. Modify environment variables vim /etc/profile Add the following export PATH=/usr/local/mysql/bin:$PATH source /etc/profile# 4. Create users Catalog Configuration file [[email protected] mysql]# useradd mysql[[email protected] mysql]# mkdir -p /data/3306/data[[email protected] mysql]# chown -R mysql.mysql /data[[email protected] mysql]# vim /etc/my.cnf[mysqld]user=mysqlbasedir=/usr/local/mysqldatadir=/data/3306/datasocket=/tmp/mysql.sock[mysql]socket=/tmp/mysql.sock# 5. Initialization data If there is no configuration file : mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data If there is a configuration file : [[email protected] data]# mysqld --initialize-insecure # 6. Ready to start the script [[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld[[email protected] ~]# /etc/init.d/mysqld stopShutting down MySQL... SUCCESS! [[email protected] ~]# /etc/init.d/mysqld startStarting MySQL.. SUCCESS! [[email protected] ~]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS! [[email protected] ~]# /etc/init.d/mysqld statusSUCCESS! MySQL running (12134)

2. Basic management

2.1 User management

2.1.1 effect

1. To log in to MySQL

2. To manage MySQL thing [ps: What is MySQL thing ??]

2.1.2 Define

Grammar : User name @' White list '

What is a white list ??  answer :IP Address range  

Common forms :

[email protected]'%'
[email protected]'localhost'
[email protected]'10.0.0.%'
[email protected]'10.0.0.2'

2.1.3 Manage users

1. Query users

 

-- Query users mysql> select user,host ,authentication_string ,plugin from mysql.user;+------------------+-----------+------------------------------------------------------------------------+-----------------------+| user | host | authentication_string | plugin |+------------------+-----------+------------------------------------------------------------------------+-----------------------+| mysql.infoschema | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password || mysql.session | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password || mysql.sys | localhost | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password || root | localhost | | caching_sha2_password |+------------------+-----------+------------------------------------------------------------------------+-----------------------+

 

Be careful : plugin, Encryption plug-in , stay 8.0 And then we did an upgrade ,caching_sha2_password, The safety has increased .

It will cause many old client programs to be unable to connect to MySQL. The earlier version was mysql_native_password.

2. Create users / Modify user / Delete user

-- Create users mysql> create user [email protected]'10.0.0.%' identified by '123';mysql> create user [email protected]'10.0.0.%' identified with mysql_native_password by '123';-- Modify user mysql> alter user [email protected]'10.0.0.%' identified with mysql_native_password by '123';mysql> alter user [email protected]'10.0.0.%' account lock;mysql> alter user [email protected]'10.0.0.%' account unlock;-- Delete user mysql> drop user [email protected]'10.0.0.%';

Be careful : 8.0 After that , Users can only be created before authorization .

2.2 License management

2.2.1 List of licenses

mysql> show privileges;

The most common license :

1.ALL ? It doesn't contain grant option

2.select ,insert ,update ,delete

2.2.2 Licensing and recycling rights

-- Authorization mysql> grant all on *.* to [email protected]'10.0.0.%';-- Inquiry permission mysql> show grants for [email protected]'10.0.0.%';-- Recycling licenses mysql> revoke drop on *.* from [email protected]'10.0.0.%' ;

As for the scope of the license :

*.* : All tables under all libraries

luffy.*: All tables in a single library

luffy.user: Single table

2.3 Connection management

2.3.1 socket File connection

-- Premise : It needs to be built in advance localhost Users of the white list [[email protected] ~]# mysql -uroot -p -S /tmp/mysql.sock

2.3.2 TCP/IP The way

-- Premise You need to log in to the client IP Join the white list [[email protected] ~]# mysql -uroot -p123 -h 10.0.0.111 -P3306

2.4 Configuration Management

2.4.1 Offline configuration

-- Configure file application order [[email protected] ~]# mysqld --help --verbose |grep my.cnf/etc/my.cnf ---> /etc/mysql/my.cnf ---> /usr/local/mysql/etc/my.cnf --> ~/.my.cnf 
-- Configure file structure [[email protected] ~]# cat /etc/my.cnf
[mysqld]user=mysqlbasedir=/usr/local/mysqldatadir=/data/3306/datasocket=/tmp/mysql.sock[mysql]socket=/tmp/mysql.sock

Be careful : Modify configuration file , Restart the database .

2.4.2 Online configuration

-- Modify through special configuration command .mysql> set global innodb_buffer_pool_size=16777216;
-- View all arguments that can be configured online show variables show variables like '%date%';

3.MySQL The architecture of

Not much , Directly above .

1. Connection layer

The wire layer has three functions :

1. Provide connection protocol : Socket Archives ,TCP/IP

2. Verify user identity / Authorization Form .

3. The connection layer provides a connection with sql The thread of layer interaction

2.SQL Layer

SQL There are six layers :

1. From the receiving layer sql Sentence

2. Verification sql Sentence syntax

3. Verification sql The semantics of a sentence (DDL,DQL,DML,DCL)

4. Parser : analysis sql Sentence , Generate execution plan

5. Optimizer : Choose the best one from the execution plan

Optimization ???? Optimization ( Logic optimization , Physical optimization ( Indexes )

6. Actuators : Execute the selected SQL Plan

1. Create threads that interact with the storage engine layer

2. What will be carried out sql Statement to the storage engine layer

3.Engine Layer

effect : Responsible for interacting with disks

4.SQL

4.1 What is SQL?

General language for relational databases . Structured query language .[ps: What is structured query language ?]

4.2 SQL_MODE

Commonly used SQL_MODE Arguments :[ps:SQL_MODE Detailed explanation ]

mysql> select @@sql_mode;+-----------------------------------------------------------------------------------------------------------------------+| @@sql_mode |+-----------------------------------------------------------------------------------------------------------------------+| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |+-----------------------------------------------------------------------------------------------------------------------+

Emphasis :  ONLY_FULL_GROUP_BY ,5.7 Version new features .

4.3 Data type

Pay special attention to :

char(10) Fixed length

varchar(10) Lengthen

Other detailed data types :[ps:MySQL Data type in ]

4.4 Character set

utf8 Save up to three byte characters

utf8mb4 Save up to four byte characters [emoji expression ]

4.5 SQL Species

DDL : Data definition language

DML : Data operation language

What is DDL( Data definition language ?), What is DML( Data operation language ?):[ps:DDL and DML The definition of ]

4.6 DDL Application specification of

4.6.1 To the library (Database) The operation of

Ku :
create database

drop database

alter database

Regulate :
a. The production system is disabled drop operation

b. Do not use system reserved characters for library names , Don't use capital letters , Don't start with a number .

c. To build a library is to explicitly set the character set .

4.6.2 Antithetical table (Table) The operation of

create table

Regulate :

Do not use system reserved characters for table names , Don't use capital letters , Don't start with a number .ob_user; Don't exceed 18 Character .

Data type :

Appropriate Short Enough

Be careful :

Each table should have a primary key .

Each column is as non empty as possible , Or set a default value

Each column should be annotated .

Storage engine usage InnoDB Character set utf8mb4

alter table

Main uses :

New column

Delete column

Suo Yin

Delete index

This type

About alter table One more thing to know :

8.0 before :Online DDL It needs to be done during the business period . Or use PT-OSC.

8.0 After that : New columns can be added directly .

drop table It's not necessary to use .

4.7 About DDL/DML and MySQL Problems in the implementation phase

prepare  MDL X Block all DML Write DDL

exec      S Demote shared lock Don't block DML , Blocking DDL

commit  MDL X Block all DML Write DDL

5. Index and execution plan

5.1 What is index ?

It's like a catalog in a book . Optimize the query (select update  delete)

5.2 Index type

BTREE *****

RTREE( Spatial data index )

HASH( Hash index )

FTEXT( Full-text index )

5.3 BTREE Structural understanding

b-tree
b+tree(b*tree) --> Enhanced version

5.4 MySQL How to apply BTREE?

5.4.1 Cluster index

1. What is clustering index ?

InnoDB in , Table data file itself is press B+Tree An index structure of an organization , Clustering index is to construct a cluster according to the primary key of each table B+ Tree , At the same time, the leaf node stores the row record data of the whole table , The leaf node of a clustered index is also called a data page . This feature determines that the data in the index organization table is also a part of the index ;

2. The construction condition of clustering index ?

Primary Key / Unique+not null / RowID

3. The construction details of clustering index ?

Leaf node (Leaf): When entering data , It will follow the logical order of clustering index , Stored in physically continuous multiple data pages . So we have leaf nodes . And store the two-way index of adjacent leaf nodes .
Branch nodes (No-Leaf): Select the leaf node ID The scope of + Indicators .
The root node (ROOT) : No-leaf Node's ID Scope + Indicators

4. The optimization effect of clustering index ?

Through ID When columns are used as query criteria , It will optimize .

5.4.2 Secondary index

...

&n

版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210122011417505M.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云