Mysql内存管理_Mysql缓冲池内存预热

 

在关闭实例重新启动数据库时,可以预热上次关闭时的内存数据,防止磁盘读增加I/O,可以配置如下参数 在关闭实例时dump一个ib_buffer_pool文件 来存放上次关闭时的内存数据  再次启动实例时加载进去

 

--1、参数配置如下:

#启动MySQL服务时,MySQL将本地热数据加载到InnoDB缓冲池中 预热#
innodb_buffer_pool_load_at_startup = 1

#停止MySQL服务时,InnoDB将InnoDB缓冲池中的热数据保存到本地硬盘#
innodb_buffer_pool_dump_at_shutdown = 1

#关闭mysql服务时,转储活跃使用的innodb buffer pages的比例,默认25%;配合innodb_buffer_pool_load_at_startup和innodb_buffer_pool_dump_at_shutdown 两个参数同时使用#
#如果启用新的参数比如40 ,每个innodb buffer pool instance中有100个 ,每次转储每个innodb buffer 实例中的40个pages#
innodb_buffer_pool_dump_pct = 40

--2、测试如下:

--1)、第一次启动数据库
[root@hostmysql-m ~]# mysql -uroot -pXXX
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 4
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

mysql> use flydb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

--第一次查询数据为0.11秒
mysql> select count(1) from test_conver_table where b='1111';
+----------+
| count(1) |
+----------+
|        1 |
+----------+
1 row in set (0.11 sec)

--第二次查询数据为0秒,因为数据已加载到innodb_buffer_pool缓冲池中
mysql> select count(1) from test_conver_table where b='1111';
+----------+
| count(1) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

mysql> exit
Bye


--2)、kill -9 因强制杀掉mysqld服务,此时不生产ib_buffer_pool
[root@hostmysql-m ~]#  kill -9 4540
[root@hostmysql-m ~]# service mysqld start
Starting mysqld:                                           [  OK  ]


--3)、第二次进去mysql服务
[root@hostmysql-m ~]# mysql -uroot -pXXX
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 4
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

mysql> select count(1) from test_conver_table where b='1111';
ERROR 1046 (3D000): No database selected
mysql> use flydb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

--第一次查询时 依然用了0.05秒,说明数据没有加载到缓冲池中
mysql> select count(1) from test_conver_table where b='1111';
+----------+
| count(1) |
+----------+
|        1 |
+----------+
1 row in set (0.05 sec)

mysql> exit
Bye


--4)、service mysqld restart 正常的重启或者关闭mysqld 服务,可产生ib_buffer_pool文件,存放关闭时实例的内存数据
[root@hostmysql-m ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

[root@hostmysql-m ~]# ll /var/lib/mysql/ib_buffer_pool
-rw-r----- 1 mysql mysql 1122 Dec 29 17:00 /var/lib/mysql/ib_buffer_pool


--5)、第三次进入mysql服务
[root@hostmysql-m ~]# mysql -uroot -pXXX
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 4
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

mysql> use flydb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

--第一次查询时 用了0秒,说明数据已经通过预热方式 加载到了缓冲池中
mysql> select count(1) from test_conver_table where b='1111';
+----------+
| count(1) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

 

你可能感兴趣的:(Mysql,基本管理,Mysql—基础功能学习)