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

  1. # cat /etc/issue
  2. CentOS release 6.5 (Final)
  3. yum -y install lrzsz
  4. mysql依赖libaio库,需要安装这些依赖库
  5. # vim /etc/sysctl.conf
  6. vm.swappiness = 0
  7. # sysctl -p
  8. # cat /sys/block/sda/queue/scheduler
  9. noop anticipatory [deadline] cfq
  10. # vim /etc/profile
  11. export HISTTIMEFORMAT='%F %T '
  12. # source /etc/profile
  13. # vim /etc/sysconfig/clock
  14. ZONE=Asia/Shanghai
  15. UTC=false
  16. ARC=false
  17. # rm /etc/localtime
  18. rm: remove regular file `/etc/localtime'? y
  19. # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  20. # date
  21. Wed Apr 17 10:49:52 CST 2019
  22. # vim /etc/selinux/config
  23. SELINUX=disabled
  24. # setenforce 0
  25. # vim /etc/security/limits.conf
  26. mysql soft nofile 65535
  27. mysql hard nofile 65535
  28. # service iptables stop
  29. # chkconfig iptables off
  30. # id mysql
  31. id: mysql: No such user
  32. # rpm -qa|grep -i mysql
  33. mysql-libs-5.1.71-1.el6.x86_64
  34. # rpm -ev mysql-libs-5.1.71-1.el6.x86_64 --nodeps
  35. # groupadd mysql
  36. # useradd -g mysql mysql
  37. # passwd mysql
  38. # vim /home/mysql/.bash_profile
  39. export LANG=en_US.UTF-8
  40. export PATH=/usr/local/mysql/bin:$PATH
  41. export MYSQL_PS1="(\u@\h:\p) [\d]> "
  42. # source /home/mysql/.bash_profile
  43. # mkdir -p /data/mysqldata/{3306/{data,tmp,binlog,slave,log/iblog},backup,scripts}
  44. # tar xvf mysql-8.0.14-linux-glibc2.12-x86_64.tar
  45. # tar xvJf mysql-8.0.14-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
  46. # ln -s mysql-8.0.14-linux-glibc2.12-x86_64 mysql
  47. # chown -R mysql:mysql /usr/local/mysql/
  48. # chown -R mysql:mysql /data/mysqldata/
  49. [mysql@DSI 3306]$ vim my.cnf
  50. [mysql@DSI 3306]$ mkdir -p /data/mysqldata/loadfile
  51. [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
  52. [mysql@DSI 3306]$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
  53. [1] 5254
  54. [mysql@DSI 3306]$ 2019-04-17T03:21:06.651957Z mysqld_safe Logging to '/data/mysqldata/3306/log/mysql-error.log'.
  55. 2019-04-17T03:21:06.673989Z mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data
  56. [mysql@DSI 3306]$ ps -ef|grep mysql
  57. 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
  58. 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
  59. [mysql@DSI 3306]$ cat /data/mysqldata/3306/log/mysql-error.log |grep "root@localhost"
  60. 2019-04-17T11:20:50.506529+08:00 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: #Fki/+cl7HdI
  61. [mysql@DSI 3306]$ /usr/local/mysql/bin/mysql -uroot -p'#Fki/+cl7HdI' -S /data/mysqldata/3306/mysql.sock
  62. mysql: [Warning] Using a password on the command line interface can be insecure.
  63. Welcome to the MySQL monitor. Commands end with ; or \g.
  64. Your MySQL connection id is 8
  65. Server version: 8.0.14
  66.  
  67. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  68.  
  69. Oracle is a registered trademark of Oracle Corporation and/or its
  70. affiliates. Other names may be trademarks of their respective
  71. owners.
  72. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  73.  
  74. (root@localhost:mysql.sock) [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '***';
  75. Query OK, 0 rows affected (0.00 sec)
  76. (root@localhost:mysql.sock) [(none)]> flush privileges;
  77. Query OK, 0 rows affected (0.00 sec)
  78. (root@localhost:mysql.sock) [(none)]> show databases;
  79. +--------------------+
  80. | Database |
  81. +--------------------+
  82. | information_schema |
  83. | mysql |
  84. | performance_schema |
  85. | 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 |

  1. 创建用户
  2. (root@localhost:mysql.sock) [employees]> create user if not exists 'system'@'10.15%' identified with mysql_native_password by '****';
  3. (root@localhost:mysql.sock) [employees]> grant all privileges on *.* to 'system'@'10.15%';
  4. (root@localhost:mysql.sock) [employees]> show create user 'system'@'10.15%'; ##查询创建用户语句
  5. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  6. | CREATE USER for system@10.15% |
  7. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  8. | 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 |
  9. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  10. (root@localhost:mysql.sock) [employees]> alter user 'system'@'10.15%' password expire interval 90 day; ##设置过期时间
  11. 创建角色
  12. (root@localhost:mysql.sock) [employees]> create role 'app_read_only','app_writes','app_developer';
  13. (root@localhost:mysql.sock) [employees]> grant select on employees.* to 'app_read_only';
  14. (root@localhost:mysql.sock) [employees]> grant insert,update,delete on employees.* to 'app_writes';
  15. (root@localhost:mysql.sock) [employees]> grant all on employees.* to 'app_developer';
  16. (root@localhost:mysql.sock) [employees]> create user emp_read_only identified by 'emp_passs';
  17. (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

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

公用表达式(CTE)

  1. with cte as(select year(from_date) as year,sum(salary) as sum from salaries group by year)
  2. 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
  3. cte as q1,cte as q2
  4. where q1.year=q2.year-1;

递归cte

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

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

  1. CREATE TABLE `employees_01` (
  2. `emp_no` int(11) NOT NULL,
  3. `birth_date` date NOT NULL,
  4. `first_name` varchar(14) NOT NULL,
  5. `last_name` varchar(16) NOT NULL,
  6. `gender` enum('M','F') NOT NULL,
  7. `hire_date` date NOT NULL,
  8. `full_name` varchar(30) as (concat(first_name,' ',last_name)),
  9. PRIMARY KEY (`emp_no`),
  10. key `name` (`first_name`,`last_name`)
  11. ) 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

  1. --行号
  2. MYSQL> select concat(first_name, " ",last_name) as full_name,salary,row_number()over(order by salary desc) as 'rank' from employees
  3. join salaries on salaries.emp_no=employees.emp_no limit 10;
  4. +-------------------+--------+------+
  5. | full_name | salary | rank |
  6. +-------------------+--------+------+
  7. | Tokuyasu Pesch | 158220 | 1 |
  8. | Tokuyasu Pesch | 157821 | 2 |
  9. | Honesty Mukaidono | 156286 | 3 |
  10. | Xiahua Whitcomb | 155709 | 4 |
  11. | Sanjai Luders | 155513 | 5 |
  12. | Tsutomu Alameldin | 155377 | 6 |
  13. | Tsutomu Alameldin | 155190 | 7 |
  14. | Tsutomu Alameldin | 154888 | 8 |
  15. | Tsutomu Alameldin | 154885 | 9 |
  16. | Willard Baca | 154459 | 10 |
  17. +-------------------+--------+------+
  18. --分隔 parition
  19. select year(hire_date) hire_date_year ,salary,row_number()over(PARTITION by year(hire_date) order by salary desc) as 'rank' from employees
  20. join salaries on salaries.emp_no=employees.emp_no order by salary desc limit 10;
  21. +----------------+--------+------+
  22. | hire_date_year | salary | rank |
  23. +----------------+--------+------+
  24. | 1985 | 158220 | 1 |
  25. | 1985 | 157821 | 2 |
  26. | 1986 | 156286 | 1 |
  27. | 1985 | 155709 | 3 |
  28. | 1987 | 155513 | 1 |
  29. | 1985 | 155377 | 4 |
  30. | 1985 | 155190 | 5 |
  31. | 1985 | 154888 | 6 |
  32. | 1985 | 154885 | 7 |
  33. | 1985 | 154459 | 8 |
  34. +----------------+--------+------+
  35. -第一个、最后一个和第n个值
  36. select year(hire_date) hire_date_year,salary,rank()over w as 'rank',
  37. first_value(salary) over w as 'first',
  38. nth_value(salary,3) over w as 'third',
  39. last_value(salary) over w as 'last'
  40. from employees join salaries on salaries.emp_no=employees.emp_no
  41. window w as (partition by year(hire_date) order by salary desc)
  42. order by salary desc limit 10;
  43. +----------------+--------+------+--------+--------+--------+
  44. | hire_date_year | salary | rank | first | third | last |
  45. +----------------+--------+------+--------+--------+--------+
  46. | 1985 | 158220 | 1 | 158220 | NULL | 158220 |
  47. | 1985 | 157821 | 2 | 158220 | NULL | 157821 |
  48. | 1986 | 156286 | 1 | 156286 | NULL | 156286 |
  49. | 1985 | 155709 | 3 | 158220 | 155709 | 155709 |
  50. | 1987 | 155513 | 1 | 155513 | NULL | 155513 |
  51. | 1985 | 155377 | 4 | 158220 | 155709 | 155377 |
  52. | 1985 | 155190 | 5 | 158220 | 155709 | 155190 |
  53. | 1985 | 154888 | 6 | 158220 | 155709 | 154888 |
  54. | 1985 | 154885 | 7 | 158220 | 155709 | 154885 |
  55. | 1985 | 154459 | 8 | 158220 | 155709 | 154459 |
  56. +----------------+--------+------+--------+--------+--------+

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引入了通用表空间,是共享的表空间,可以存储多个表的数据。

  1. (root@localhost:mysql.sock) [employees]> create tablespace ts1 add datafile 'ts1.ibd' engine=innodb;
  2. Query OK, 0 rows affected (0.02 sec)
  3. (root@localhost:mysql.sock) [employees]> create table table_gen_ts1(id int primary key) tablespace ts1;
  4. Query OK, 0 rows affected (0.03 sec)
  5.  
  6. 降序索引
  7. (root@localhost:mysql.sock) [employees]> explain select * from employees order by first_name asc,last_name desc limit 10;
  8. +----+-------------+-----------+------------+------+---------------+------+---------+------+--------+----------+----------------+
  9. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
  10. +----+-------------+-----------+------------+------+---------------+------+---------+------+--------+----------+----------------+
  11. | 1 | SIMPLE | employees | NULL | ALL | NULL | NULL | NULL | NULL | 299733 | 100.00 | Using filesort |
  12. +----+-------------+-----------+------------+------+---------------+------+---------+------+--------+----------+----------------+
  13. 1 row in set, 1 warning (0.00 sec)
  14.  
  15. (root@localhost:mysql.sock) [employees]> alter table employees add index name_desc(first_name asc,last_name desc);
  16. Query OK, 0 rows affected (0.94 sec)
  17. Records: 0 Duplicates: 0 Warnings: 0
  18.  
  19. (root@localhost:mysql.sock) [employees]> explain select * from employees order by first_name asc,last_name desc limit 10;
  20. +----+-------------+-----------+------------+-------+---------------+-----------+---------+------+------+----------+-------+
  21. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
  22. +----+-------------+-----------+------------+-------+---------------+-----------+---------+------+------+----------+-------+
  23. | 1 | SIMPLE | employees | NULL | index | NULL | name_desc | 124 | NULL | 10 | 100.00 | NULL |
  24. +----+-------------+-----------+------------+-------+---------------+-----------+---------+------+------+----------+-------+
  25.  
  26. sys schema
  27. 启用一个计数器
  28. (root@localhost:mysql.sock) [employees]> call sys.ps_setup_enable_instrument('statement');
  29. +------------------------+
  30. | summary |
  31. +------------------------+
  32. | Enabled 22 instruments |
  33. +------------------------+
  34. 1 row in set (0.00 sec)
  35. --按类型列出买个主机的语句(insert/select)
  36. (root@localhost:mysql.sock) [employees]> select statement,total,total_latency,rows_sent,rows_examined,rows_affected,
  37. -> full_scans from sys.host_summary_by_statement_type where host='localhost' order by total desc limit 5;
  38. +-------------------+-------+---------------+-----------+---------------+---------------+------------+
  39. | statement | total | total_latency | rows_sent | rows_examined | rows_affected | full_scans |
  40. +-------------------+-------+---------------+-----------+---------------+---------------+------------+
  41. | set_option | 221 | 19.45 ms | 0 | 0 | 0 | 0 |
  42. | insert | 168 | 51.21 s | 0 | 0 | 3919015 | 0 |
  43. | select | 112 | 30.29 s | 11757148 | 57562351 | 0 | 56 |
  44. | Field List | 94 | 42.97 ms | 0 | 0 | 0 | 0 |
  45. | show_create_table | 50 | 10.32 ms | 0 | 0 | 0 | 0 |
  46. +-------------------+-------+---------------+-----------+---------------+---------------+------------+
  47. --按类型列出每个用户的语句
  48. (root@localhost:mysql.sock) [employees]> select statement,total,total_latency,rows_sent,rows_examined,rows_affected,
  49. -> full_scans from sys.user_summary_by_statement_type order by total desc limit 5;
  50. +-------------+-------+---------------+-----------+---------------+---------------+------------+
  51. | statement | total | total_latency | rows_sent | rows_examined | rows_affected | full_scans |
  52. +-------------+-------+---------------+-----------+---------------+---------------+------------+
  53. | set_option | 221 | 19.45 ms | 0 | 0 | 0 | 0 |
  54. | insert | 168 | 51.21 s | 0 | 0 | 3919015 | 0 |
  55. | select | 113 | 30.29 s | 11757153 | 57562980 | 0 | 57 |
  56. | Field List | 94 | 42.97 ms | 0 | 0 | 0 | 0 |
  57. | show_status | 56 | 133.97 ms | 24864 | 49728 | 0 | 56 |
  58. +-------------+-------+---------------+-----------+---------------+---------------+------------+
  59. --冗余索引
  60. select * from sys.schema_redundant_indexes where table_name='employees';
  61. --未使用的索引
  62. (root@localhost:mysql.sock) [employees]> select * from sys.schema_unused_indexes where object_name='employees';
  63. +---------------+-------------+------------+
  64. | object_schema | object_name | index_name |
  65. +---------------+-------------+------------+
  66. | employees | employees | name_desc |
  67. +---------------+-------------+------------+
  68. --每个主机执行的语句
  69. (root@localhost:mysql.sock) [employees]> select * from sys.host_summary order by statements desc limit 5;
  70. +-------------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+----------------+------------------------+
  71. | 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 |
  72. +-------------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+----------------+------------------------+
  73. | localhost | 950 | 1.39 m | 87.53 ms | 97 | 24110 | 1.28 s | 1 | 12 | 1 | 262.35 KiB | 7.12 GiB |
  74. | 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 |
  75. +-------------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+----------------+------------------------+
  76. --对表的统计
  77. select * from sys.schema_table_statistics limit 1;
  78. --对带缓冲区(buffer)的表的统计
  79. select * from sys.schema_table_statistics_with_buffer limit 10;
  80. --语句分析
  81. select * from sys.statement_analysis order by exec_count desc limit 1;
  82. --消耗最大的tmp_disk_tables
  83. select * from sys.statement_analysis order by tmp_disk_tables desc limit 1;

mysql 8.0 初识的更多相关文章

  1. [MySQL 5.6] 初识5.6的optimizer trace

      在MySQL5.6中,支持将执行的SQL的查询计划树记录下来,目前来看,即使对于非常简单的查询,也会打印出冗长的查询计划,看起来似乎不是很可读,不过对于一个经验丰富,对查询计划的生成过程比较了解的 ...

  2. MYSQL之数据库初识、安装详解、sql语句基本操作

    目录 MYSQL之数据库初识及安装详解 1.什么是数据库? 1.什么是数据?(data) 2.什么是数据库?(databases,简称DB) 2.为什要用数据库? 3.什么是数据库管理系统?(Data ...

  3. mysql 5.0.46安装配置

    http://os.chinaunix.net/a2008/0801/986/000000986346.shtml RPM包和源码包存放位置 /usr/local/src 源码包编译安装位置(pref ...

  4. RedHat下apache\ftp\mysql 4.0 的安装方法

    RedHat下安装这三个服务的方法大同小异 Apache服务: 找到Apache安装包: rpm -ivh httpd-2.0.40-21.i386.rpm 等待安装完成即可 检查安装结果: rpm ...

  5. MySQL 8.0.0 版本发布,亮点都在这了!

    导读 MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司.目前MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开 ...

  6. Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://127.0.0.1:3306/test'

    原来的配置如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  7. MySQL :: MySQL 5.0 Reference Manual :: 14.4 The MEMORY (HEAP) Storage Engine

    MySQL :: MySQL 5.0 Reference Manual :: 14.4 The MEMORY (HEAP) Storage Engine The MEMORY (HEAP) Stora ...

  8. MySQL 6.0安装图解

    MySQL 6.0安装图解 由于免费,MySQL数据库在项目中用的越来越广泛,而且它的安全性能也特别高,不亚于oracle这样的大型数据库软件.可以简单的说,在一些中小型的项目中,使用MySQL ,P ...

  9. What's New In MySQL 8.0

        由于8.0内有很多C++11特性.需要gcc4.8版本以上.Rhel6系列默认gcc是4.7.在安装gcc6.1之后仍然检查不过. 原因可能是6.1版本不一定高于4.7,暂不讨论.鉴于升级gc ...

随机推荐

  1. python 输出时间

    import datetime print(datetime.datetime.now().time())

  2. MaintainableCSS 《可维护性 CSS》 --- 约定篇

    约定 可维护的CSS具有以下约定: .<module>[-<component>][-<state>] {} 根据所讨论的模块,方括号是可选的.这里有些例子: /* ...

  3. npm 报错: npm ERR! Please try running this command again as root/Administrator.

    解决方法: 1. 需要删除npmrc文件. 强调:不是nodejs安装目录npm模块下的那个npmrc文件 而是在C:\Users\{账户}\下的.npmrc文件.. 2. 在win8或者win10下 ...

  4. 雷林鹏分享:Ruby File 类和方法

    Ruby File 类和方法 File 表示一个连接到普通文件的 stdio 对象.open 为普通文件返回该类的一个实例. 类方法 序号方法 & 描述 1File::atime( path) ...

  5. Win32 基本文件读写操作

    https://www.cnblogs.com/Clingingboy/archive/2011/05/10/2042645.html

  6. Appium 自动化测试(7) -- Appium 服务器初始化参数设置

    Desired Capabilities Desired capabilities 是一些发送给 Appium 服务器的键值对集合 (比如 map 或 hash),告诉服务器我们想要启动什么类型的自动 ...

  7. vue 报错 Cannot read property '__ob__' of undefined的解决方法

    记不清第n次遇到这个错误了,但是脑子就是不好用,记不住解决办法啊,每次都要找好久才能找到错误,网上还一篇篇的全是错误答案......所以写篇随笔,记录下,方便大家也方便我自己. 网上有人说是组件循环了 ...

  8. python高级编程之列表推导式

    1. 一个简单的例子 在Python中,如果我们想修改列表中所有元素的值,可以使用 for 循环语句来实现. 例如,将一个列表中的每个元素都替换为它的平方: >>> L = [1, ...

  9. PostgreSQL查询长连接

    apple=# select pid, backend_start, xact_start, query_start, waiting, state, backend_xid from pg_stat ...

  10. C# #if, #else和#endif预处理指令

        #if 使您可以开始条件指令,测试一个或多个符号以查看它们是否计算为 true.如果它们的计算结果确实为true,则编译器将计算位于 #if 与最近的 #endif 指令之间的所有代码.例如, ...