9

我有一个 1.9GB 的 MySQL innodb 数据库,通过以下命令显示。

SELECT table_schema "Data Base Name"
     , sum( data_length + index_length ) / 1 048 576 
       as "Data Base Size in MB"
     , sum( data_free )/ 1 048 576  
       as "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ; 

+--------------------+----------------------+------------------+
| Data Base Name     | Data Base Size in MB | Free Space in MB |
+--------------------+----------------------+------------------+
| database_name      |        1959.73437500 |   31080.00000000 | 

我的问题是:

  1. 这是否意味着如果我将 innodb_buffer_pool_size 设置为 2GB 或更大,整个数据库可以加载到内存中,因此需要从磁盘请求中读取更少?

  2. 31GB的可用空间是什么意思?

  3. 如果可以分配给 innodb_buffer_pool_size 的最大 RAM 为 1GB,是否可以指定将哪些表加载到内存中,同时保持其他表始终从磁盘读取?

提前致谢。

4

2 回答 2

7
  1. 不完全是。InnoDB 缓冲池用于缓冲读取和写入。如果您的大部分访问都被读取,那么大部分访问将被缓存并且需要更少的磁盘访问。
  2. 可能是这个错误,它没有很好地记录,但我认为 data_free 是 innodb 文件中的可用空间(如果你写的比这个 InnoDB 更多,则必须扩大数据文件)。
  3. 不,但 InnoDB 会自动缓存您最常访问的数据,因此无论如何它应该具有最佳效果。

如果您需要更好的性能,请考虑使用memcached作为缓存层来完全消除数据库访问。

于 2010-03-21T11:41:39.257 回答
2
  1. 最好担心有足够的内存来缓存内存中的索引,并将数据留在磁盘上。如果每次都必须从磁盘读取索引,则数据库性能会受到很大影响——远远超过以后从磁盘检索所需数据的开销。
  2. InnoDB data files are created at a fixed size, with the option to autoextend them (create extra files) if they get full. You can see what the per-file size is with show variables like 'innodb_data_file_path'. The free space reported is how much of the current data files is unused. In your case, you've got 2gigs of data stored in (most likely) 32gigs of InnodB data files, leaving 30gig available.
  3. Is there any reason you want to bypass InnoDB's own cacheing logic to pin specific tables in ram? The cache will naturally tend to keep the most frequently accessed data in ram already, and performance will no doubt suffer if you force it to keep less-used data instead of the most popular.
于 2010-03-22T18:26:09.837 回答