mysql 8.0 初识

1 下载并安装mysql 8.0
官网下载比较慢,这里选择163的镜像
http://mirrors.163.com/mysql/Downloads/MySQL-8.0/
下载版本mysql-8.0.14-linux-glibc2.12-x86_64.tar
vbox

# cat /etc/issue
CentOS release 6.5 (Final)
yum -y install lrzsz
mysql依赖libaio库,需要安装这些依赖库
# vim /etc/sysctl.conf
vm.swappiness = 0
# sysctl -p
# cat /sys/block/sda/queue/scheduler
noop anticipatory [deadline] cfq
# vim /etc/profile
export HISTTIMEFORMAT='%F %T '
# source /etc/profile
# vim /etc/sysconfig/clock
ZONE=Asia/Shanghai
UTC=false
ARC=false
# rm /etc/localtime
rm: remove regular file `/etc/localtime'? y
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# date
Wed Apr 17 10:49:52 CST 2019
# vim /etc/selinux/config
SELINUX=disabled
# setenforce 0
# vim /etc/security/limits.conf
mysql soft nofile 65535 
mysql hard nofile 65535
# service iptables stop
# chkconfig iptables off
# id mysql
id: mysql: No such user
# rpm -qa|grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
# rpm -ev mysql-libs-5.1.71-1.el6.x86_64 --nodeps
# groupadd mysql
# useradd -g mysql mysql
# passwd mysql
# vim /home/mysql/.bash_profile
export LANG=en_US.UTF-8
export PATH=/usr/local/mysql/bin:$PATH
export MYSQL_PS1="(\u@\h:\p) [\d]> "
# source /home/mysql/.bash_profile
# mkdir -p /data/mysqldata/{3306/{data,tmp,binlog,slave,log/iblog},backup,scripts}
# tar xvf mysql-8.0.14-linux-glibc2.12-x86_64.tar
# tar xvJf mysql-8.0.14-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
# ln -s mysql-8.0.14-linux-glibc2.12-x86_64 mysql
# chown -R mysql:mysql /usr/local/mysql/
# chown -R mysql:mysql /data/mysqldata/
[mysql@DSI 3306]$ vim my.cnf 
[mysql@DSI 3306]$ mkdir -p /data/mysqldata/loadfile
[mysql@DSI 3306]$ /usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data --user=mysql --initialize
[mysql@DSI 3306]$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
[1] 5254
[mysql@DSI 3306]$ 2019-04-17T03:21:06.651957Z mysqld_safe Logging to '/data/mysqldata/3306/log/mysql-error.log'.
2019-04-17T03:21:06.673989Z mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data
[mysql@DSI 3306]$ ps -ef|grep mysql
mysql     5254  7566  0 11:21 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf
mysql     6507  5254  2 11:21 pts/1    00:00:01 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/data/mysqldata/3306/log/mysql-error.log --open-files-limit=65535 --pid-file=DSI.pid --socket=/data/mysqldata/3306/mysql.sock --port=3306
[mysql@DSI 3306]$ cat /data/mysqldata/3306/log/mysql-error.log |grep "root@localhost"
2019-04-17T11:20:50.506529+08:00 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: #Fki/+cl7HdI
[mysql@DSI 3306]$ /usr/local/mysql/bin/mysql -uroot -p'#Fki/+cl7HdI' -S /data/mysqldata/3306/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.14

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

(root@localhost:mysql.sock) [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '***';
Query OK, 0 rows affected (0.00 sec)
(root@localhost:mysql.sock) [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(root@localhost:mysql.sock) [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |

mysql 8.0的分区表只支持innodb、ndbcluster,其他引擎的不支持
下载安装mysql工具集
# wget https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-utilities-1.6.5-1.el6.noarch.rpm

加载示例数据
# wget 'https://codeload.github.com/datacharmer/test_db/zip/master' -O master.zip
(root@localhost:mysql.sock) [employees]> show tables;
+----------------------+
| Tables_in_employees |
+----------------------+
| current_dept_emp |
| departments |
| dept_emp |
| dept_emp_latest_date |
| dept_manager |
| employees |
| salaries |
| titles |
在mysql8.0,已经删掉了.frm表结构文件
[root@DSI employees]# ll
total 182520
-rw-r-----. 1 mysql mysql 131072 Apr 17 14:21 departments.ibd
-rw-r-----. 1 mysql mysql 26214400 Apr 17 14:22 dept_emp.ibd
-rw-r-----. 1 mysql mysql 131072 Apr 17 14:22 dept_manager.ibd
-rw-r-----. 1 mysql mysql 23068672 Apr 17 14:21 employees.ibd
-rw-r-----. 1 mysql mysql 109051904 Apr 17 14:23 salaries.ibd
-rw-r-----. 1 mysql mysql 28311552 Apr 17 14:22 titles.ibd
使用正则表达式查询
(root@localhost:mysql.sock) [employees]> select count(*) from employees where first_name rlike '^christ';
+----------+
| count(*) |
+----------+
| 1157 |

创建用户
(root@localhost:mysql.sock) [employees]> create user if not exists 'system'@'10.15%' identified with mysql_native_password by '****';
(root@localhost:mysql.sock) [employees]> grant all privileges on *.* to 'system'@'10.15%';
(root@localhost:mysql.sock) [employees]> show create user 'system'@'10.15%'; ##查询创建用户语句
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for system@10.15%                                                                                                                                                                                                                                      |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'system'@'10.15%' IDENTIFIED WITH 'mysql_native_password' AS '*4DB42A770506EA05234DECCD02E3FCCB77D03B5C' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
(root@localhost:mysql.sock) [employees]> alter user 'system'@'10.15%' password expire interval 90 day; ##设置过期时间
创建角色
(root@localhost:mysql.sock) [employees]> create role 'app_read_only','app_writes','app_developer';
(root@localhost:mysql.sock) [employees]> grant select on employees.* to 'app_read_only';
(root@localhost:mysql.sock) [employees]> grant insert,update,delete on employees.* to 'app_writes';
(root@localhost:mysql.sock) [employees]> grant all on employees.* to 'app_developer';
(root@localhost:mysql.sock) [employees]> create user emp_read_only identified by 'emp_passs';
(root@localhost:mysql.sock) [employees]> grant 'app_read_only' to 'emp_read_only'@'%';

获取有关数据库和表的信息
use information_schema;
静态元数据:table_schema、table_name、table_type、engine
动态表元数据:auto_incremant、avg_row_length、data_free
在mysql8.0中,动态表元数据将默认被缓存,可以通过information_schema_stats进行配置,并且可以改为
set @@global.information_schema_status='LATEST';
(root@localhost:mysql.sock) [employees]> use information_schema;
(root@localhost:mysql.sock) [information_schema]> show tables;
--tables\columns\files\innodb_tablespaces\innodb_tablestats\processlist

使用JSON
从mysql 5.7开始,mysql支持JavaScript对象表示(JSON)数据类型,JSON文档以二进制格式存储
(root@localhost:mysql.sock) [employees]> create table emp_details(emp_no int primary key,details json);
insert into emp_details(emp_no,details)
values(1,'{"location":"IN","phone":"+123456768","email":"abc@xx.com","address":{"line1":"abc","line2":"xys street","city":"BBB","PIN":"12345"}}');
(root@localhost:mysql.sock) [employees]> select emp_no, details->'$.address.PIN' pin from emp_details;
+--------+---------+
| emp_no | pin     |
+--------+---------+
|      1 | "12345" |
+--------+---------+

公用表达式(CTE)

with cte as(select year(from_date) as year,sum(salary) as sum from salaries group by year)
select q1.year,q2.year as next_year,q1.sum,q2.sum as next_sum,100*(q2.sum-q1.sum)/q1.sum as pct from 
cte as q1,cte as q2
where q1.year=q2.year-1;

递归cte

with recursive cte (n) AS(select 1
union ALL
select n+1 from cte where n<5)
select * from cte;

生成列--的值是根据列定义中包含的表达式计算得出的,两种类型
--virtual,当从表中读取记录时,将计算该列--这个虚拟列不占用任何空间
--stored,当向表中写入新记录时,将计算列并将其作为常规列存储在表中

CREATE TABLE `employees_01` (
  `emp_no` int(11) NOT NULL,
  `birth_date` date NOT NULL,
  `first_name` varchar(14) NOT NULL,
  `last_name` varchar(16) NOT NULL,
  `gender` enum('M','F') NOT NULL,
  `hire_date` date NOT NULL,
  `full_name` varchar(30) as (concat(first_name,' ',last_name)),
  PRIMARY KEY (`emp_no`),
  key `name` (`first_name`,`last_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

窗口函数

Name         Description
CUME_DIST()     Cumulative distribution value
DENSE_RANK()    Rank of current row within its partition, without gaps
FIRST_VALUE()    Value of argument from first row of window frame
LAG()           Value of argument from row lagging current row within partition
LAST_VALUE()      Value of argument from last row of window frame
LEAD()         Value of argument from row leading current row within partition
NTH_VALUE()     Value of argument from N-th row of window frame
NTILE()                          Bucket number of current row within its partition.
PERCENT_RANK()       Percentage rank value
RANK()                         Rank of current row within its partition, with gaps
ROW_NUMBER()         Number of current row within its partition

--行号
MYSQL> select concat(first_name, " ",last_name) as full_name,salary,row_number()over(order by salary desc) as 'rank' from employees
join salaries on salaries.emp_no=employees.emp_no limit 10;
+-------------------+--------+------+
| full_name         | salary | rank |
+-------------------+--------+------+
| Tokuyasu Pesch    | 158220 |    1 |
| Tokuyasu Pesch    | 157821 |    2 |
| Honesty Mukaidono | 156286 |    3 |
| Xiahua Whitcomb   | 155709 |    4 |
| Sanjai Luders     | 155513 |    5 |
| Tsutomu Alameldin | 155377 |    6 |
| Tsutomu Alameldin | 155190 |    7 |
| Tsutomu Alameldin | 154888 |    8 |
| Tsutomu Alameldin | 154885 |    9 |
| Willard Baca      | 154459 |   10 |
+-------------------+--------+------+
--分隔 parition
select year(hire_date) hire_date_year ,salary,row_number()over(PARTITION by year(hire_date) order by salary desc) as 'rank' from employees
join salaries on salaries.emp_no=employees.emp_no order by salary desc limit 10;
+----------------+--------+------+
| hire_date_year | salary | rank |
+----------------+--------+------+
|           1985 | 158220 |    1 |
|           1985 | 157821 |    2 |
|           1986 | 156286 |    1 |
|           1985 | 155709 |    3 |
|           1987 | 155513 |    1 |
|           1985 | 155377 |    4 |
|           1985 | 155190 |    5 |
|           1985 | 154888 |    6 |
|           1985 | 154885 |    7 |
|           1985 | 154459 |    8 |
+----------------+--------+------+
-第一个、最后一个和第n个值
select year(hire_date) hire_date_year,salary,rank()over w as 'rank',
first_value(salary) over w as 'first',
nth_value(salary,3) over w as 'third',
last_value(salary) over w as 'last'
from employees join salaries on salaries.emp_no=employees.emp_no
window w as (partition by year(hire_date) order by salary desc)
order by salary desc limit 10;
+----------------+--------+------+--------+--------+--------+
| hire_date_year | salary | rank | first  | third  | last   |
+----------------+--------+------+--------+--------+--------+
|           1985 | 158220 |    1 | 158220 |   NULL | 158220 |
|           1985 | 157821 |    2 | 158220 |   NULL | 157821 |
|           1986 | 156286 |    1 | 156286 |   NULL | 156286 |
|           1985 | 155709 |    3 | 158220 | 155709 | 155709 |
|           1987 | 155513 |    1 | 155513 |   NULL | 155513 |
|           1985 | 155377 |    4 | 158220 | 155709 | 155377 |
|           1985 | 155190 |    5 | 158220 | 155709 | 155190 |
|           1985 | 154888 |    6 | 158220 | 155709 | 154888 |
|           1985 | 154885 |    7 | 158220 | 155709 | 154885 |
|           1985 | 154459 |    8 | 158220 | 155709 | 154459 |
+----------------+--------+------+--------+--------+--------+

mysql 8.0 配置mysql
静态参数和动态参数,一些参数已经不再支持,详细参考官方文档

https://downloads.mysql.com/docs/refman-8.0-en.pdf

Server and Status Variables and Options Added, Deprecated, or Removed in MySQL 8.0
Options and Variables Introduced in MySQL 8.0

--innodb_buffer_pool_size 可以动态调节大小,不再需要重启
--innodb_buffer_pool_instances
--innodb_log_file_size 更改不需要重启
更改数据目录

(root@localhost:mysql.sock) [employees]> show variables like '%datadir%';
+---------------+----------------------------+
| Variable_name | Value |
+---------------+----------------------------+
| datadir | /data/mysqldata/3306/data/ |
+---------------+----------------------------+
--停止mysql,创建新目录(权限),rsync -av /data/mysqldata/3306/data/ /new_datadir

二进制日志
--binlog_expire_logs_seconds
--expire_logs_days : Purge binary logs after this many days. Deprecated as of MySQL 8.0.3

SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 693
#190417 14:21:46 server id 20190417 end_log_pos 775 CRC32 0x15ee14ef Query thread_id=33 exec_time=0 error_code=0
SET TIMESTAMP=1555482106/*!*/;
BEGIN
/*!*/;
--server id 20190417,产生 改事件的服务器的serverid
--end_log_pos 下一个事件的开始位置
--thread_id 指示那个线程执行了该事件
--exec_time 在主服务器上,它代表执行事件的时间,在从服务器上,代表从服务器的最终执行时间与主服务器的开始执行时间之间的差值,这个差值可以作为备份相对于主服务器滞后多少的指标
--error_code 执行事件的结果

[mysql@DSI backup]$ mysqldump -uroot -p -S /data/mysqldata/3306/mysql.sock --databases employees --single-transaction --default-character-set=utf8 --master-data=2> /data/mysqldata/backup/employees_backup01.sql

# yum install glib2-devel mysql-devel zlib-devel pcre-devel cmake gcc-c++ git
git clone https://github.com/maxbube/mydumper.git
cmake .
make
make install
--# yum install https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper-0.9.5-1.el6.x86_64.rpm
$ /usr/local/bin/mydumper -uroot -p -S /data/mysqldata/3306/mysql.sock -B employees -o /data/mysqldata/backup/mydumper_bak
[mysql@DSI ~]$ /usr/local/bin/mydumper -u root -p *** -S /data/mysqldata/3306/mysql.sock -B employees -o /data/mysqldata/backup/mydumper_bak
[mysql@DSI ~]$ cd /data/mysqldata/backup/mydumper_bak/
[mysql@DSI mydumper_bak]$ ll
total 168324
-rw-rw-r--. 1 mysql mysql 138 Apr 17 17:28 employees.current_dept_emp-schema.sql
-rw-rw-r--. 1 mysql mysql 950 Apr 17 17:28 employees.current_dept_emp-schema-view.sql
-rw-rw-r--. 1 mysql mysql 332 Apr 17 17:28 employees.departments-schema.sql
-rw-rw-r--. 1 mysql mysql 351 Apr 17 17:28 employees.departments.sql
-rw-rw-r--. 1 mysql mysql 127 Apr 17 17:28 employees.dept_emp_latest_date-schema.sql
-rw-rw-r--. 1 mysql mysql 845 Apr 17 17:28 employees.dept_emp_latest_date-schema-view.sql
-rw-rw-r--. 1 mysql mysql 594 Apr 17 17:28 employees.dept_emp-schema.sql
-rw-rw-r--. 1 mysql mysql 14160012 Apr 17 17:28 employees.dept_emp.sql
-rw-rw-r--. 1 mysql mysql 606 Apr 17 17:28 employees.dept_manager-schema.sql
-rw-rw-r--. 1 mysql mysql 1168 Apr 17 17:28 employees.dept_manager.sql
-rw-rw-r--. 1 mysql mysql 285 Apr 17 17:28 employees.emp_details-schema.sql
-rw-rw-r--. 1 mysql mysql 343 Apr 17 17:28 employees.emp_details.sql
-rw-rw-r--. 1 mysql mysql 565 Apr 17 17:28 employees.employees_01-schema.sql
-rw-rw-r--. 1 mysql mysql 419 Apr 17 17:28 employees.employees-schema.sql
-rw-rw-r--. 1 mysql mysql 17722965 Apr 17 17:28 employees.employees.sql
-rw-rw-r--. 1 mysql mysql 455 Apr 17 17:28 employees.salaries-schema.sql
-rw-rw-r--. 1 mysql mysql 118693182 Apr 17 17:28 employees.salaries.sql
-rw-rw-r--. 1 mysql mysql 98 Apr 17 17:28 employees-schema-create.sql
-rw-rw-r--. 1 mysql mysql 466 Apr 17 17:28 employees.titles-schema.sql
-rw-rw-r--. 1 mysql mysql 21708866 Apr 17 17:28 employees.titles.sql
-rw-rw-r--. 1 mysql mysql 136 Apr 17 17:28 metadata

数据字典
数据字典是元数据,跟数据库对象,表、索引和表列,在mysql 8.0中引入,元数据的物理位置位于mysql数据库目录中的innodb独立表空间中
mysql数据字典的优点:
--以集中式数据字典模式统一存储字典数据
--删除了基于文件的元数据存储
--对字典数据的事务性、崩溃时的安全存储
--对字典对象的统一和集中缓存
--对一些information_schema表的实现进行简化和改进
--原子DDL

管理undo表空间
mysql 8.0,innodb_undo_tablespaces,动态变量
管理通用表空间
mysql 8引入了通用表空间,是共享的表空间,可以存储多个表的数据。

(root@localhost:mysql.sock) [employees]> create tablespace ts1 add datafile 'ts1.ibd' engine=innodb;
Query OK, 0 rows affected (0.02 sec)
(root@localhost:mysql.sock) [employees]> create table table_gen_ts1(id int primary key) tablespace ts1;
Query OK, 0 rows affected (0.03 sec)

降序索引
(root@localhost:mysql.sock) [employees]> explain select * from employees order by first_name asc,last_name desc limit 10;
+----+-------------+-----------+------------+------+---------------+------+---------+------+--------+----------+----------------+
| id | select_type | table     | partitions | type | possible_keys | key  | key_len | ref  | rows   | filtered | Extra          |
+----+-------------+-----------+------------+------+---------------+------+---------+------+--------+----------+----------------+
|  1 | SIMPLE      | employees | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 299733 |   100.00 | Using filesort |
+----+-------------+-----------+------------+------+---------------+------+---------+------+--------+----------+----------------+
1 row in set, 1 warning (0.00 sec)

(root@localhost:mysql.sock) [employees]> alter table employees add index name_desc(first_name asc,last_name desc);
Query OK, 0 rows affected (0.94 sec)
Records: 0  Duplicates: 0  Warnings: 0

(root@localhost:mysql.sock) [employees]> explain select * from employees order by first_name asc,last_name desc limit 10;
+----+-------------+-----------+------------+-------+---------------+-----------+---------+------+------+----------+-------+
| id | select_type | table     | partitions | type  | possible_keys | key       | key_len | ref  | rows | filtered | Extra |
+----+-------------+-----------+------------+-------+---------------+-----------+---------+------+------+----------+-------+
|  1 | SIMPLE      | employees | NULL       | index | NULL          | name_desc | 124     | NULL |   10 |   100.00 | NULL  |
+----+-------------+-----------+------------+-------+---------------+-----------+---------+------+------+----------+-------+

sys schema
启用一个计数器
(root@localhost:mysql.sock) [employees]> call sys.ps_setup_enable_instrument('statement');
+------------------------+
| summary                |
+------------------------+
| Enabled 22 instruments |
+------------------------+
1 row in set (0.00 sec)
--按类型列出买个主机的语句(insert/select)
(root@localhost:mysql.sock) [employees]> select statement,total,total_latency,rows_sent,rows_examined,rows_affected,
    -> full_scans from sys.host_summary_by_statement_type where host='localhost' order by total desc limit 5;
+-------------------+-------+---------------+-----------+---------------+---------------+------------+
| statement         | total | total_latency | rows_sent | rows_examined | rows_affected | full_scans |
+-------------------+-------+---------------+-----------+---------------+---------------+------------+
| set_option        |   221 | 19.45 ms      |         0 |             0 |             0 |          0 |
| insert            |   168 | 51.21 s       |         0 |             0 |       3919015 |          0 |
| select            |   112 | 30.29 s       |  11757148 |      57562351 |             0 |         56 |
| Field List        |    94 | 42.97 ms      |         0 |             0 |             0 |          0 |
| show_create_table |    50 | 10.32 ms      |         0 |             0 |             0 |          0 |
+-------------------+-------+---------------+-----------+---------------+---------------+------------+
--按类型列出每个用户的语句
(root@localhost:mysql.sock) [employees]> select statement,total,total_latency,rows_sent,rows_examined,rows_affected,
    -> full_scans from sys.user_summary_by_statement_type  order by total desc limit 5;
+-------------+-------+---------------+-----------+---------------+---------------+------------+
| statement   | total | total_latency | rows_sent | rows_examined | rows_affected | full_scans |
+-------------+-------+---------------+-----------+---------------+---------------+------------+
| set_option  |   221 | 19.45 ms      |         0 |             0 |             0 |          0 |
| insert      |   168 | 51.21 s       |         0 |             0 |       3919015 |          0 |
| select      |   113 | 30.29 s       |  11757153 |      57562980 |             0 |         57 |
| Field List  |    94 | 42.97 ms      |         0 |             0 |             0 |          0 |
| show_status |    56 | 133.97 ms     |     24864 |         49728 |             0 |         56 |
+-------------+-------+---------------+-----------+---------------+---------------+------------+
--冗余索引
select * from sys.schema_redundant_indexes where table_name='employees';
--未使用的索引
(root@localhost:mysql.sock) [employees]> select * from sys.schema_unused_indexes where object_name='employees';
+---------------+-------------+------------+
| object_schema | object_name | index_name |
+---------------+-------------+------------+
| employees     | employees   | name_desc  |
+---------------+-------------+------------+
--每个主机执行的语句
(root@localhost:mysql.sock) [employees]> select * from sys.host_summary order by statements desc limit 5;
+-------------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+----------------+------------------------+
| host        | statements | statement_latency | statement_avg_latency | table_scans | file_ios | file_io_latency | current_connections | total_connections | unique_users | current_memory | total_memory_allocated |
+-------------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+----------------+------------------------+
| localhost   |        950 | 1.39 m            | 87.53 ms              |          97 |    24110 | 1.28 s          |                   1 |                12 |            1 | 262.35 KiB     | 7.12 GiB               |
| 10.15.7.126 |        206 | 19.82 s           | 96.19 ms              |         102 |    11543 | 413.85 ms       |                   1 |                 7 |            1 | 1.34 MiB       | 454.41 MiB             |
+-------------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+----------------+------------------------+
--对表的统计
select * from sys.schema_table_statistics limit 1;
--对带缓冲区(buffer)的表的统计
select * from sys.schema_table_statistics_with_buffer limit 10;
--语句分析
select * from sys.statement_analysis order by exec_count desc limit 1;
--消耗最大的tmp_disk_tables
select * from sys.statement_analysis order by tmp_disk_tables desc limit 1;

 

posted @ 2019-04-17 17:36  春困秋乏夏打盹  阅读(304)  评论(0编辑  收藏  举报