Day128: MySQL advanced:

iR-Poke 2021-01-21 23:21:23
day128 day mysql advanced


1. Introduction and installation

2. Basic management

2.1 User management

2.2 Rights management

2.3 Connection management

2.4 Configuration Management

3.MySQL Architecture of


5. Index and execution plan

1. Introduction and installation

1.1 Database classification

RDBMS( Relational database ):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 expandable / Short for high performance database )

Representative works :spanner  PolarDB(X)  TDSQL  TiDB  gaussian

1.2 MySQL Branch




4. Cloud manufacturers

1.3 MySQL obtain

1.4 MySQL install

# 1. decompression 
[root@localhost opt]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
# 2. Soft connection 
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 user Catalog The configuration file 
[root@localhost mysql]# useradd mysql
[root@localhost mysql]# mkdir -p /data/3306/data
[root@localhost mysql]# chown -R mysql.mysql /data
[root@localhost mysql]# vim /etc/my.cnf
# 5. Initialization data 
 If there is no profile :
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
If there is a configuration file :
[root@localhost data]# mysqld --initialize-insecure 
# 6. Ready to start script 
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# /etc/init.d/mysqld stop
Shutting down MySQL... SUCCESS!
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@localhost ~]# /etc/init.d/mysqld status
SUCCESS! MySQL running (12134)

2. Basic management

2.1 User management

2.1.1 effect

1. Used to log in MySQL

2. Used to manage MySQL object [ps: What is? MySQL object ??]

2.1.2 Definition

grammar : user name @' White list '

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

Common form :


2.1.3 Manage users

1. Query the user


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


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

Many old client programs will not be able to connect to MySQL. The earlier version was mysql_native_password.

2. Create user / Modify the user / Delete user

-- Create user 
mysql> create user root@'10.0.0.%' identified by '123';
mysql> create user user1@'10.0.0.%' identified with mysql_native_password by '123';
-- Modify the user 
mysql> alter user root@'10.0.0.%' identified with mysql_native_password by '123';
mysql> alter user user1@'10.0.0.%' account lock;
mysql> alter user user1@'10.0.0.%' account unlock;
-- Delete user 
mysql> drop user user1@'10.0.0.%';

Be careful : 8.0 after , Only users can be created before authorization .

2.2 Rights management

2.2.1 Permission list

mysql> show privileges;

The most common permissions :

1.ALL ? It doesn't contain grant option ,insert ,update ,delete

2.2.2 Authorization and recall rights

-- to grant authorization 
mysql> grant all on *.* to root@'10.0.0.%';
-- Query authority 
mysql> show grants for root@'10.0.0.%';
-- Recycling permissions 
mysql> revoke drop on *.* from root@'10.0.0.%' ;

About the scope of authority :

*.* : All tables under all libraries

luffy.*: All tables in a single library

luffy.user: Single table

2.3 Connection management

2.3.1 socket The file

-- Premise : It needs to be created in advance localhost White list users 
[root@localhost ~]# 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 
[root@localhost ~]# mysql -uroot -p123 -h -P3306

2.4 Configuration Management

2.4.1 Offline configuration

-- Configuration file application order 
[root@localhost ~]# mysqld --help --verbose |grep my.cnf
/etc/my.cnf ---> /etc/mysql/my.cnf ---> /usr/local/mysql/etc/my.cnf --> ~/.my.cnf 
-- Configuration file structure 
[root@localhost ~]# cat /etc/my.cnf
[mysqld] user=mysql basedir=/usr/local/mysql datadir=/data/3306/data socket=/tmp/mysql.sock [mysql] socket=/tmp/mysql.sock

Be careful : Modify the 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 parameters that can be configured online 
show variables
show variables like '%date%';

3.MySQL Architecture of

Not much to say , Directly above .

1. adjoining course

There are three functions of connecting layer :

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

2. Verify user identity / Authorization Form .

3. The connection layer provides an interface with sql Layer interaction threads

2.SQL layer

SQL There are six layers :

1. Receive from the connection layer sql sentence

2. verification sql Sentence syntax

3. verification sql The semantics of the statement (DDL,DQL,DML,DCL)

4. Parser : analysis sql sentence , Generate execution plan

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

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

6. actuator : Execute the selected SQL plan

1. Threads that interact with the storage engine layer

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

3.Engine layer

effect : Responsible for interacting with disk


4.1 What is? SQL?

Relational databases are universal Language . Structured query language .[ps: What is a structured query language ?]


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

mysql> select @@sql_mode;
| @@sql_mode |

a key :  ONLY_FULL_GROUP_BY ,5.7 Version new features .

4.3 data type

Particular attention :

char(10) Fixed length

varchar(10) Lengthening

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

4.4 Character set

utf8 Save up to three bytes of characters

utf8mb4 Save up to four bytes of 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 Library (Database) The operation of

library :
create database

drop database

alter database

standard :
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 Counter table (Table) The operation of

create table

standard :

Do not use system reserved characters for table names , Don't use capital letters , Don't start with a number .ob_user; Not more than 18 character .

data type :

Appropriate Brief Adequate

Be careful :

Each table should have a primary key .

Each column should be as non empty as possible , Or set the default value

Each column should be annotated .

Storage engine use InnoDB Character set utf8mb4

alter table

Main uses :

Add columns

Delete column

Suo Yin

Delete index

This type of

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 : Adding columns can be done 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 in DDL

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

commit  MDL X Block all DML write in DDL

5. Index and execution plan

5.1 What is index ?

It's like a catalog in a book . Optimized 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) --> Enhanced Edition

5.4 MySQL How to apply BTREE?

5.4.1 Cluster index

1. What is a clustered index ?

InnoDB in , Table data file itself is by pressing B+Tree An index structure of an organization , Clustering index is based on The primary key of each table constructs one B+ Trees , At the same time, the leaf node stores the whole Table row records data , The leaf node of the clustered index is also called Data pages . This feature determines the index organization. The data in the table is also 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 you enter data , It will follow the logical order of clustering index , Stored in multiple data pages that are physically continuous . So we have leaf nodes . And store two-way pointers of adjacent leaf nodes .
Branch nodes (No-Leaf): Select the leaf node ID The scope of the + The pointer .
The root node (ROOT) : No-leaf Node ID Range + The pointer

4. The optimization effect of clustering index ?

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

5.4.2 Secondary index




  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课程百度云