Mysql.mysql

The introduction

Why do we need to learn mysql? The first database management system that computer majors learn is mysql. Large, medium and small Internet companies and some traditional industry companies generally use mysql as a relational database management system. Of course, now domestic large factories also have research and development for their own business relational database, but are standing on the shoulders of giants to do. Therefore, the necessity of learning mysql does not need to be discussed too much.

Learning about mysql is not only about how to use it, but also about why to use it, as well as the usual optimization and high availability practices for production environments. So, let’s demystify mysql.


Introduction to the

Mysql is an open source, correspondingly fast, reliable, scalable, and easy to use relational database management system developed and supported by Oracle Corporation.

What is a database? A database is a place where data is stored, and it can be stored in different forms; It’s essentially a file system that stores data in a specific format. You can add, delete, modify, and query a database using SQL.

What is a database management system? Database management system is to manipulate and manage the large software database, used to establish, use and maintain the database; Unified database management ensures database security and integrity.

What is a relational database? A relational database is a database that stores data in rows and columns.

history

  • MySQL’s history can be traced back to 1979, when a programmer named Monty Widenius worked for a small company called TcX and designed a reporting tool in BASIC that could run on a 4MHz computer with 16KB of memory. At the time, it was just a very low-level, reports-only storage engine called Unireg.
  • In 1990, TcX began receiving requests from its customers for SQL support for its apis. Monty borrows directly from mSQL code and integrates it into its own storage engine. Disappointingly, the results were less than satisfactory, and determined to rewrite a SQL support yourself.
  • In 1996, MySQL 1.0 was released as an internal release for a small group of people. By October 1996, MySQL 3.11.1 was released (MySQL didn’t have 2.x), and at first only binary versions were available under Solaris. A month later, a Linux version appeared. Over the next two years, MySQL was ported to each platform in turn.
  • MySQL AB was founded in Sweden in 1999 ~ 2000. Monty hired a couple of people to work with Sleepycat to create the Berkeley DB engine, and since BDB supports transactions, MySQL has since started to support transactions.
  • In 2000, MySQL not only released its own source code, but also adopted the GPL(GNU General Public License) License, officially entering the open source world. In April of the same year, MySQL cleaned up the old storage engine ISAM and named it MyISAM.
  • In 2001, Heikki Tuuri’s InnoDB storage engine was integrated, which not only supports transaction but also row-level locking. This engine later proved to be the most successful MySQL transaction storage engine. MySQL and InnoDB are officially integrated in version 4.0.
  • In December 2003, MySQL 5.0 was released, providing views, stored procedures, and more.
  • In January 2008, [MySQL AB was acquired by Sun for $1 billion], MySQL database entered the era of Sun. In Sun era, Sun company carried out a lot of promotion, optimization, Bug repair and so on.
  • In November 2008, MySQL 5.1 was released, providing partitioning, event management, and row-based replication and disk-based NDB clustering systems, while fixing a number of bugs.
  • Oracle’s acquisition of Sun for $7.4 billion in April 2009 brought MySQL into the Oracle era, while InnoDB, a third-party storage engine, was acquired by Oracle in 2005.
  • In December 2010, [MySQL 5.5 was released], the major new features include semi-synchronous replication and support for SIGNAL/RESIGNAL exception handling. [Most importantly, InnoDB storage engine has finally become the default storage engine for MySQL.] MySQL 5.5 is not a simple release update after two years, but rather an enhancement of all aspects of MySQL at the enterprise level. Oracle also promises that MySQL 5.5 and future releases will remain open source under the GPL license.

SQL

SQL, short for Structured Query Language, is a programming Language used to Query, update, and manage relational database systems. SEQUEL is the predecessor of the well-known relational database prototype System R. As a standard language for accessing relational databases, SQL has been widely used since its inception. It is not only supported by well-known large-scale commercial database products such as Oracle, DB2, Sybase and SQL Server, but also supported by many open source database products such as PostgreSQL and MySQL. Even smaller products like Access support SQL. The NoSQL systems that have flourished in recent years initially claimed that SQL was no longer needed, and then had to be modified to Not Only SQL to embrace SQL.

A brief history of SQL:

1986, ANSI X3.135-1986, ISO/IEC 9075:1986, SQL-86

1989, ANSI X3.135-1989, ISO/IEC 9075:1989, SQL-89

1992, ANSI X3.135-1992, ISO/IEC 9075:1992, SQL-92 (SQL2)

1999, ISO/IEC 9075:1999, SQL:1999 (SQL3)

2003, ISO/IEC 9075:2003, SQL:2003

2008, ISO/IEC 9075:2008, SQL:2008

2011, ISO/IEC 9075:2011, SQL:2011

SQL92 standard needs us to master, because it involves SQL the most basic and the most core of some content; Not only mysql but also other databases, based on international SQL standards such as SQL92 or SQL99, have extended some of their SQL statements, such as the limit keyword in mysql.

SQL language Classification

Data Definition Language (DDL) : Objects used to define a database: libraries, tables, columns, and so on. Keywords: CREATE, ALTER, DROP, truncate, etc

Common DDL:

CREATE DATABASE: CREATE DATABASE

CREATE a database TABLE: CREATE TABLE

ALTER TABLE ALTER TABLE

DROP a database TABLE: DROP TABLE

CREATE a query command: CREATE VIEW

Delete TABLE contents: TRUNCATE TABLE

Data Manipulation Language (DML) : Used to process the data content of a database. Keywords: INSERT, DELETE, update, etc

Common DML:

INSERT data: INSERT INTO TABLE

DELETE data: DELETE FROM TABLE

UPDATE TABLE SET

Data Query Language (DQL) : Used to query the data content of the database. Keywords: SELECT, FROM, WHERE, etc

Data Control Language (DCL) : Used to define database access and security levels and user creation. Keywords: Grant, etc

Common DCL:

GRANT ALL PRIVILEGES ON. TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;

DDL

Database operations

  1. Creating a database

    create database database_name;
    create database database_name character setThe character set.# sample
    create database samir character set UTF8;
    Copy the code
  2. Viewing a Database

    show databases;
    show create database database_name;
    
    # sample
    show create database samir;
    Copy the code
  3. Deleting a Database

    drop database database_name;
    
    # sample
    drop database samir;
    Copy the code
  4. Other database operations

    use database_name;
    select database(a);# sample
    use samir;
    Copy the code

Table operation

  1. Create a table

    create table table_name(
        field_name typeConstraints, field_nametypeConstraints, field_nametypeConstraints);The primary key is not null. The primary key is not null.
    The only difference between a primary key constraint and a unique constraint is that the unique constraint can be NULL
    
    # sample
    CREATE TABLE `test` (
    	`id`  int(11) NOT NULL AUTO_INCREMENT COMMENT 'id' ,
    	`name`  varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'name' ,
    	`dept`  varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'department' ,
    	`age`  int(3) NOT NULL DEFAULT 0 COMMENT 'age' ,
    	`nick`  varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'nickname' ,
    	PRIMARY KEY (`id`),
    	UNIQUE INDEX `index_test` (`name`) USING BTREE 
    )
    ENGINE=InnoDB
    DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
    ;
    Copy the code
  2. See the table

    show tables;
    desc test;
    Copy the code

  3. Delete table

    drop table table_name;
    
    # sample
    drop table test;
    Copy the code
  4. Modify the table

    # increase the column
    alter table table_name add field_name typeConstraints;# delete columns
    alter table table_name drop field_name;
    
    Modify column types and constraints
    alter table table_name modify field_name typeConstraints;Change the column name
    alter table table_name change old_field_name new_field_name typeConstraints;Alter table name
    rename table old_table_name to new_table_name;
    
    Alter table character set
    alter table table_name character setThe character set.Copy the code

DML

  1. Insert records

    insert into table_name (field_name1, field_name2, ...) values(value1, value1, ...) ;insert into table_name values(value1, value1, ...) ;insert into table_name (field_name1, field_name2, ...) select field_name1, field_name2, ... from table_name;
    insert into table_name select * from table_name;
    
    # sample
    insert into test (`name`, dept, age, nick) values ('Joe'.'E-commerce Projects Division'.28.'Zhang SAN Feng');
    Copy the code
  2. Delete records

    delete from table_name;
    delete from table_name where. ;# sample
    delete from test where id = 1;
    Copy the code
  3. Modify the record

    update table_name set field_name1 = vaule1, field_name2 = vaule2, ... ;
    update table_name set field_name1 = vaule1, field_name2 = vaule2, ... where. ;# sample
    update test set `name` = 'bill', nick = Li Siwa where id = 2;
    Copy the code

DQL

  1. Query log

    select * from table_name;
    
    # sample
    select * from test;
    Copy the code

  2. Common aggregate function

    # count -- Returns the total number of records in the query
    select count(0) from test;
    
    # sum - sum
    select sum(age) from test;
    
    # length -- calculates the length of the string
    select length(nick) from test where `name` = 'Joe';
    
    # concat -- merge multiple strings
    select concat(`name`.':', dept) from test;
    
    
    Copy the code

    More a collection of functions used to view – novice tutorial: www.runoob.com/mysql/mysql…

  3. grouping

    select dept from test group by dept;
    Copy the code

    select group_concat(name), dept from test group by dept;
    Copy the code

  4. The sorting

    The default is ASC
    select * from test order by id;
    
    select * from test order by id desc;
    Copy the code
  5. paging

    # limit is not part of the SQL92 standard and is often used with Order BY
    select * from test order by id limit 0.1;
    Copy the code

    # offset Specifies the offset
    select * from test limit 1 offset 2;
    Copy the code

  6. The subquery

    Subqueries allow one query to be nested within another query, typically in select, after FROM, or where.
    Copy the code
  7. like

    select * from test where `name` like 'l %';
    Copy the code

  8. having

    select group_concat(`name`) name.length(group_concat(`name`)) namelen, dept from test group by dept having length(`name`) > 7;
    Copy the code

  9. union

    select * from test where `name` = 'Joe' union select * from test where age = 36;
    Copy the code

DCL

  1. See mysql Installation – Common Commands

The data type

Numeric types

type The size of the Range (signed) Scope (unsigned) use Java data types
TINYINT 1 byte (128127) (0255). A small integer value java.lang.Integer
SMALLINT 2 bytes (-32 768,32 767) ,65 (0 535). Large integer value java.lang.Integer
MEDIUMINT 3 bytes (-8 388 608,8 388 607) (0,16 777 215) Large integer value java.lang.Integer
INT or an INTEGER 4 bytes (-2,147,483,648, 2,147,483,647) (0,4 294 967 295) Large integer value java.lang.Long
BIGINT 8 bytes (-9,223,372,036,854,775,808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) Maximum integer value java.math.BigInteger
FLOAT 4 bytes (-3.402 823 466 E+38, -1.494 369 E+38), 0, (1.494 369 E+38, 3.402 823 466 369 E+38) 0, (1.175 494 369 E-38, 3.402 823 466 E+38) Single-precision floating point value java.lang.Float
DOUBLE 8 bytes (-1.797 693 134 862 391 7e +308, -2.797 858 858 391 4 e-308), 0, (2.797 858 858 391 4 e-308, 1.797 693 134 862 315 7 E+308) 0, (1.797 693 134 862 315 7 E+308) Double – precision floating – point value java.lang.Double
DECIMAL For DECIMAL(M,D), M+2 if M>D otherwise D+2 Depends on the values of M and D Depends on the values of M and D Small numerical java.math.BigDecimal

The date type

type Size (bytes) The scope of format use Java data types
DATE 3 The 1000-01-01/1000-01-01 YYYY-MM-DD Date value java.sql.Date
TIME 3 ‘- 838:59:59’/’ 838:59:59 ‘ HH:MM:SS Time value or duration java.sql.Time
YEAR 1 1901/2155 YYYY Year value java.sql.Date
DATETIME 8 The 1000-01-01 00:00:00/1000-01-01 23:59:59 YYYY-MM-DD HH:MM:SS Mixes date and time values java.sql.Timestamp
TIMESTAMP 4 1970-01-01 00:00:00/2038 end time is no2147483647Second, Beijing timeThe 2038-1-19 11:14:07At 03:14:07 GMT on January 19, 2038 YYYYMMDD HHMMSS Mix date and time values, time stamps java.sql.Timestamp

Character types

type The size of the use Java data types
CHAR 0-255 bytes Fixed length string java.lang.String
VARCHAR 0-65535 bytes Variable length string java.lang.String
TINYBLOB 0-255 bytes A binary string of up to 255 characters java.lang.byte[]
TINYTEXT 0-255 bytes Short text string java.lang.String
BLOB 0-65 535 bytes Long text data in binary form java.lang.byte[]
TEXT 0-65 535 bytes Long text data java.lang.String
MEDIUMBLOB 0-16 777 215 bytes Medium length text data in binary form java.lang.byte[]
MEDIUMTEXT 0-16 777 215 bytes Medium length text data java.lang.String
LONGBLOB 0-4 294 967 295 bytes Very large text data in binary form java.lang.byte[]
LONGTEXT 0-4 294 967 295 bytes Maximal text data java.lang.String

architecture

Logical structure analysis

  1. Connected to

    Mysql-connector can be used to connect to the mysql server in any language.

  2. Manage services and tools

    This is the entry point for the database operation engineer or DBA to operate the database. Example: MySQL Utilities, which provides a set of command-line tools for maintaining and managing MySQL servers; Which include the

    • Management tools (Clone, copy, Compare, difference, Export, import)
    • Replication tools (installation, configuration)
    • General tools (disk usage, redundant indexes, search metadata)
  3. The connection pool

    Authentication of customer initiated connection requests, connection pool maintenance, and memory management.

  4. SQL interface

    Receive SQL languages such as data definition language, data manipulation language, stored procedures and triggers.

  5. The SQL parser

    The SQL parser consists of two modules, one: lexical analysis (the function is to decompose the entire query into multiple elements); Second: syntax rules (find combinations of SQL syntax rules, generate a sequence, and execute the code associated with those rules). This module throws an exception when an ERROR is reported when writing SQL.

    Lexical analysis divides SQL statements into elements one by one. Syntax rules generate corresponding data structures based on the syntax rules defined by mysql and store them in THD ->lex objects.

    select `name`, dept from test where age > 18;
    Copy the code

  6. The SQL optimizer

    The SQL optimizer generates an execution plan based on the data structure of the THD -> LEX object. Example: Use the best index, the small table associated with the large table, the where condition from left to right to find the strongest filtering priority.

  7. SQL cache

    The SQL query results are stored in the form of a map. The key is the value after the SQL is hashed.

  8. The storage engine

    Mysql storage engine is used for tables, we commonly used mysql storage engine is InnoDB and MyISam.

    • This section describes various storage engines

      Storage Engine Name introduce
      myisam No transaction support, no row lock support; Fast insertion and query speed
      innodb Default storage engine from mysql5.6, transaction support, row lock support, foreign key support, slightly slower than MyISam
      memory Memory storage engine, insert, query, update super fast, but data stored in memory; One is unsafe, and the other is a linear increase in memory usage and data volume
      isam As a forerunner of myiasm
      merge Multiple tables can be combined into one table, which is suitable for the storage of large-scale data
      archive Compressed data is used to store historical data with a large amount of data. Only insertion and query are supported
      cvs Storage based on SVC data format
      falcon The new storage engine, which supports transactions, is said to be a replacement for InnoDB
    • Innodb vs. Myisam

      The difference between innodb myisam
      Storing files .frm table definition file; Ibd data files and index files .frm table definition file; .myd data file; Myi Index file
      The lock Table lock, row lock Table locks
      The transaction support Does not support
      CRDU Read, write, Read more
      count Sweep the table Special storage place (add where also scan table)
      Index structure B+ Tree B+ Tree
      A foreign key support Does not support

Physical structure analysis

Log files have different functions than data files; Log files are stored in sequential I/O mode (fast recording and can only be added, wasting space), while data files are stored in random I/O mode (slow recording and saving space). Data files are stores of data and indexes; Both are stored in the /var/lib/mysql directory

  1. The log file

    # Check whether logging is enabled
    show variables like 'log_%';
    Copy the code
    • The error log

      Records the startup and shutdown logs, errors, and warnings of the mysql Server

    • Binary log

      binlog

    • General log

    • Slow Query logs

      We need to manually turn this on

    • Redo log

      redo.log

    • Roll back log

      undo.log

    • Relay log

      relay.log

  2. The data file

    # View data files
    show variables like '%datadir%';
    Copy the code

    • The FRM file

      The main storage and table related information, table definition

    • The ibd file

      An exclusive table space is used to store table data and index information. Each table corresponds to one IBD file

    • Ibdata files

      A shared table space is used to store table data and index information, and all tables are shared or multiple IBD files are used

SQL Execution sequence

select distinct <select_list> from <left_table> <join_type> join <right_table> on <join_condition> where <where_condition> group by <group_by_list> having <having_condition> order by <order_by_condition> limit <limit_number>;

- line filter
1 from <left_table>
2 on <join_condition>
3 <join_type> join <right_table> # The second and third steps are executed in a loop
4 where <where_condition> Step 4 is executed in a loop, with multiple conditions executed from left to right.
5 group by <group_by_list>
6 having <having_condition>
- column filter
7 select Select is executed after grouping
8 distinct <select_list>
Sort -
9 order by <order_by_condition>
- MySQL additional
10 limit <limit_number> The first 9 steps are SQL92 standard syntax. Limit is a syntax unique to MySQL.
Copy the code

case

# Goods and categories of goods
CREATE TABLE `item` (
	`id`  int(11) NOT NULL AUTO_INCREMENT COMMENT 'id' ,
	`name`  varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Trade Name' ,
	`itemclsid`  int(11) NOT NULL COMMENT 'Category of Goods' ,
	`price`  int(3) NOT NULL DEFAULT 0 COMMENT 'Commodity price' ,
	`description`  varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'Product Description' ,
	PRIMARY KEY (`id`),
	UNIQUE INDEX `index_test` (`name`) USING BTREE 
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
;

CREATE TABLE `itemcls` (
	`id`  int(11) NOT NULL AUTO_INCREMENT COMMENT 'id' ,
	`name`  varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Category name',
	PRIMARY KEY (`id`),
	UNIQUE INDEX `index_test` (`name`) USING BTREE 
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
;

insert into item (`name`, itemclsid, price, description)values ("iphone 4".1.6499."Apple's seminal product.");
insert into item (`name`, itemclsid, price, description)values ("iphone 12".1.6899."Apple's first 5G phone");
insert into item (`name`, itemclsid, price, description)values ("Huawei mate20".1.4399.Huawei Business Jet);
insert into item (`name`, itemclsid, price, description)values ("Huawei p20".1.4899.Huawei Camera Phone);
insert into item (`name`, itemclsid, price, description)values ("Vientiane Thermos cup".2.199."Stainless steel vacuum flask");
insert into item (`name`, itemclsid, price, description)values ("All inclusive glass".2.230."High silicon glass");

insert into itemcls(`name`) values ("Mobile phone");
insert into itemcls(`name`) values ("The cup");
Copy the code
  1. From (create virtual table -virtual_table_1)

    select * from item, itemcls; # Produces the Cartesian product
    Copy the code

  2. On (process virtual_table_1 cartesian product, produce Virtual_table_2)

    select * from item a, itemcls b where a.itemclsid = b.id;# Eliminate cartesian product
    
    # is equivalent to
    select * from item a inner join itemcls b on a.itemclsid = b.id;
    Copy the code

  3. Join (process virtual_table_2, add external column to virtual_table_2, produce Virtual_table_3)

    Insert two more pieces of data first to see the difference
    insert into item (`name`, itemclsid, price, description)values ("Morning Light marker".4.3."Better use a marker.");
    insert into itemcls(`name`) values ("Daily necessities");
    Copy the code
    # left join (left join, add external column)
    select * from item a left join itemcls b on a.itemclsid = b.id;
    Copy the code

    # right join (outer join, add outer column)
    select * from item a right join itemcls b on a.itemclsid = b.id;
    Copy the code

    # inner join (inner join, no outer column)
    select * from item a inner join itemcls b on a.itemclsid = b.id;
    Copy the code

    # out join
    select * from item a left outer join itemcls b on a.itemclsid = b.id;
    select * from item a right outer join itemcls b on a.itemclsid = b.id;
    Copy the code
  4. Where virtual_table_3 does not match virtual_table_4

    # Conditional filtering
    select * from item a left join itemcls b on a.itemclsid = b.id where price > 1;
    Copy the code

  5. Virtual_table_5 group by (virtual_table_5)

    select * from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.price;
    
    MySQL 5.7.5 and above relies on detection. If ONLY_FULL_GROUP_BY SQL mode is enabled (BY default), MySQL will reject select lists, and queries HAVING conditions or ORDER BY lists reference neither unnamed non-collection columns in the GROUP BY clause, nor rely on them functionally
    Copy the code

    select * from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.`name`;
    Copy the code

  6. Having (filter virtual_table_5 to create virtual_table_6)

    select * from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.`name` having a.`name` like 'iphone%';
    Copy the code

  7. Select virtual_table_6.1 from virtual_table_6

    select a.`name`, a.price * 0.75, a.description, b.`name` from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.`name` having a.`name` like 'iphone%';
    Copy the code

  8. Distinct (Repeatedly filter virtual_table_6.1 to generate virtual_table_6.2)

    select distinct a.`name`, a.price * 0.75, a.description, b.`name` from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.`name` having a.`name` like 'iphone%';
    Copy the code

  9. Order by (select virtual_table_6.2 from virtual_table_7)

    select distinct a.`name`, a.price * 0.75 newprice, a.description, b.`name` from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.`name` having a.`name` like 'iphone%' order by newprice;
    Copy the code

  10. Limit (select rows from virtual_table_7)

    select distinct a.`name`, a.price * 0.75 newprice, a.description, b.`name` from item a left join itemcls b on a.itemclsid = b.id where a.price > 1 group by a.`name` having a.`name` like 'iphone%' order by newprice limit 1;
    Copy the code

Mysql installation

uninstall

#### yum install
#1. Check the installed mysql
rpm -qa | grep -i mysql
yum repolist all | grep mysql

#2. Uninstall mysql
yum remove -y mysql mysql-libs mysql-common 

#3. Delete the data files in mysql
rm -rf /var/lib/mysql

#4. Delete the mysql configuration file 
rm /etc/my.cnf 

#5. Delete components
yum remove -y  mysql-community-release-el6-5.noarch 
Copy the code

The installation

#Download the RPM file 
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

#Execute the RPM source file 
rpm -ivh mysql57-community-release-el7-8.noarch.rpm

#Executing the installation file
yum install mysql-community-server 
#The following error may occur when executing the yum commandRm -f /var/run/yum.pid: rm -f /var/run/yum.pid: rm -f /var/run/yum.pid: rm -f /var/run/yum.pid: rm -f /var/run/yum.pid: rm -f /var/run/yum.pid: rm -f /var/run/yumCopy the code

Start the

systemctl start mysqld

#An error was reported during startup
SELinux is preventing /usr/sbin/mysqld from associate access on the shared memory Unknown.

vim /etc/selinux/config
#Change SELINUX=enforcing to SELINUX=disabled
reboot
Copy the code

Common commands

#You need to query the initialization password on Linux before logging in to mysql
grep password /var/log/mysqld.log 
mysql -uroot -p

#Modifying a Password Policy
set global validate_password_policy=0;

#Changing the Password Length
set global validate_password_length=1;

#Change the password of user root
set password for 'root'@'localhost' = password('123456');

#MySQL remote connection authorization 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 

#Refresh the permissions
FLUSH PRIVILEGES;

#To view the user
select user from mysql.user;
Copy the code

subsequent

Indexes, InnoDB, locks, transactions, optimizations, clustering, and sub-library sub-tables will be covered in future articles in this series