mysql super-detailed introduction to installation, architecture and basic configuration, and connection management

Introduction and installation of mysql

mysql 分支:Oracle,mariadb,percona,RDS,TX

mysql enterprise version selection: 5.7.28+ 8.0.18+

Install mysql 8.0.20

上传和解压:
https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz (软件包位置)
[root@db01 opt]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz 	
[root@db01 opt]# ln -s /opt/mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
[root@db01 mysql]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@db01 mysql]# source /etc/profile
[root@db01 mysql]# mysql -V
mysql  Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)

创建用户(mysql内部管理时需要一个非ROOT用户来进行管理)
[root@db01 ~]# useradd mysql

创建目录并授权
[root@db01 ~]# mkdir -p /data/3306/data
[root@db01 ~]# chown -R mysql. /data

准备配置文件
[root@db01 ~]# vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock

安装数据库的库文件
[root@db01 ~]# yum install libaio-devel -y

初始化数据库
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data

准备启动脚本
[root@db01 ~]# cp /usr/local/mysql/bin/mysql.server /etc/init.d/mysqld
[root@db01 ~]# systemctl enable mysqld
[root@db01 ~]# systemctl restart mysqld
[root@db01 ~]# systemctl start mysqld

此时数据库就可以正常使用
[root@db01 ~]# mysql

Mysql architecture and basic management

Mysql C/S working principle
Server: mysqld
Client: mysql mysqldump development tools (sqlyog, navicat, workbench) API

Mysql instance
mysqld + master thread + worker thread + pre-allocated memory

Mysql program structure
Server layer: connection layer SQL layer
Engine layer: FS

Mysql architecture and sql statement execution process
https://www.processon.com/view/link/60212b8ee0b34d208a6c0f8b
Insert picture description here

Mysql physical storage knowledge
Macro-recognition: The library in the database is equivalent to the table in the catalog database is equivalent to the file under the catalog
Micro-recognition: the extent area (cluster) 64 consecutive pages default 1M, page page: default 16KB continuous 4 blocks, block fast: default 4KB, 8 consecutive 512 bytes

Mysql basic management

User management
role: log in to the database, manage database objects

Definition
Username@'Whitelist': A list of IP addresses allowed to log in.

xiaoming@'localhost'   允许本地登录
xiaoming@'10.0.0.%'    允许10.0.0.0/255.255.255.0
xiaomingo@'10.0.0.0/255.255.254.0'  
xiaoming@'10.0.0.5%'    

User management

查询用户
mysql> select user,host,plugin,authentication_string from mysql.user;
创建用户
mysql> create user xiaoming@'localhost' identified by '123456';

注意:
8.0之后,不再支持grant一次性创建用户授权了.必须先建用户后授权.
8.0之后,密码插件改为caching_sha2_password,早期版本是mysql_native_password

修改用户
mysql> alter user xiaoming@'localhost' identified by '123'; (修改用户密码)
mysql> alter user xiaoming@'localhost' account lock; (上锁)
mysql> alter user xiaoming@'localhost' account unlock; (解锁)
mysql> drop user xiaoming@'localhost'; (删除用户)

Management of permissions
Role: Restrict what users can do with database objects.

查看所有的权限
mysql> show privileges;
授权表:
user  全局级别
db    单库级别
table 单表级别

例子1:给小明授权为本地的管理员
mysql> create user xiaoming@'localhost' identified with mysql_native_password by '123';
mysql> grant all on *.* to xiaoming@'localhost';

例子2:给小高授权为小高业务的业务用户
mysql> create user xiaogao@'localhost' identified with mysql_native_password by '123456';
mysql> grant select,update,detele,insert on xiaogao.* to xiaogao@'localhost';
查询小高权限
mysql> show grants for xiaogao@'localhost';
回收小高detele权限
mysql> revoke detele on xiaogao.* from xiaogao@'localhost';

Connection management

Built-in client program
socket Local socket file socket=/tmp/mysql.sock
Application:
[root@db01 ~]# mysql -uxiaoming -p123 -S /tmp/mysql.sock
Prerequisite:
xiaoming@'localhost needs to be created in advance '

TCP/IP
premise:
remote@'10.0.0.%' needs to be created in advance
mysql> create user remote@'10.0.0.%' identified by '123';
mysql> grant all on . To remote@'10.0.0. %';

Application:
[root@db01 ~]# mysql -uremote -p123 -h10.0.0.51 -P3306

Guess you like

Origin blog.csdn.net/weixin_49629796/article/details/113761763