How to increase MySQL memory limit?
来源:互联网 发布:西安麻将软件 编辑:程序博客网 时间:2024/05/18 04:01
The question – I have a lot of RAM on my machine. How can I increase the memory limits used by MySQL so that MySQL uses more memory and less virtual memory?
There are two MySQL variables that can be used to increase the memory limit. One is called key_buffer_size and the other is called query_cache_size. By increasing both of these variables, you will instruct MySQL to cache more indexes and records in RAM, thereby increasing its speed and performance. By increasing both, you will also reduce the number of major page faults that mysqld encounters.
key_buffer_size – This is the amount of memory used to cache frequently used indexes. This cache is global and accessed by all MySQL clients. The maximum allowed size is 4 GB on a 32 bit machine. MySQL recommends this value to be 25% of the total available RAM on a machine. On my Linux CentOS box, I have 2 GB of memory and I use a value of 256 mega bytes which is slightly conservative, but I have a lot of traffic which needs memory as well.
query_cache_size – This is the amount of memory that MySQL uses to cache the complete result sets of frequently used queries. The default value is 0 which means that query caching is disabled. On my Linux machine, I use a value of 16 MB which is a little less, but works fine in my case.
How to check memory limits of MySQL?
To check the values of the memory limit variables in MySQL, you can use either of the following three options:
a) Using the mysql command line admin tool
mysql -u databaseusername -p
This will give you a mysql command prompt.
To check the query cache size, use the following mysql session:
mysql> SHOW VARIABLES LIKE ‘query_cache_size’;
+——————+———-+
| Variable_name | Value |
+——————+———-+
| query_cache_size | 16777216 |
+——————+———-+
1 row in set (0.02 sec)
mysql>
To check the key_buffer_size, use the following syntax:
mysql> SHOW VARIABLES LIKE ‘key_buffer_size’;
+—————–+———–+
| Variable_name | Value |
+—————–+———–+
| key_buffer_size | 268435456 |
+—————–+———–+
1 row in set (0.00 sec)
mysql>
So this shows that I have 256 MB of key_buffer_size and 16 MB of query_cache_size.
b) Using the command line mysqladmin tool
mysqladmin -u databaseusername -p variables | grep key_buffer_size
AND
mysqladmin -u databaseusername -p variables | grep query_cache_size
This outputs:
| key_buffer_size | 268435456
| query_cache_size | 16777216
c) Using my.cnf
[~]# grep -i query_cache_size /etc/my.cnf
query_cache_size=16M
[~]#
[~]# grep -i key_buffer_size /etc/my.cnf
key_buffer_size=256M
[~]#
How to increase the memory limits of MySQL
To increase the memory limits of MySQL, you can chose to increase query_cache_size, or the key_buffer_size or both.
To increase either, first locate your my.cnf file:
root@server [/etc]# mysql –help | grep my.cnf
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
root@server [/etc]#
On my Linux box, my.cnf is located at /etc/my.cnf.
Open the file using your favorite editor:
vi /etc/my.cnf
Then add or change the following lines:
query_cache_size=16M
key_buffer_size=256M
Note that it is recommended that key_buffer_size be less than the 25% of available memory. Also, choose the query_cache_size wisely based on your available memory.
How to check free memory on a Linux box
To check free memory on your machine, use the free command:
free -mt
This outputs something like the following:
root@server [/etc]# free -mt
total used free shared buffers cached
Mem: 2048 2045 2 0 0 1431
-/+ buffers/cache: 614 1433
Swap: 2048 680 1367
Total: 4096 2725 1370
root@server [/etc]#
You should increase the query_cache_size or the key_buffer_size only if you have free memory that is unused. Note that the cached column in the free output above is considered free memory.
So play with the memory limits of MySQL and report your findings using the comments section below!
- How to increase MySQL memory limit?
- How to Increase the Memory Limit for 32-bit Applications in Windows 64-bit OS
- Increase IIS/WinXP connection limit (or how to avoid HTTP 403.9 error)
- How to work around Android’s 24 MB memory limit
- How to increase Memory usage for an App in Windows Phone
- How to Increase Your Professional Reputation
- Title: How to limit instantialization?
- Using DataReaders to Increase Speed and Reduce Memory
- How to Disable Visual Styles to Increase Performance
- How to use bonding to increase the throughput?
- Increase “Open Files Limit”
- How to increase VirtualBox Guest host Screen Size
- How to Increase CSS Misscount in single instance ASM installations
- How to properly increase ulimit -n on Lion?
- How to increase MTT Size in Mellanox HCA
- DM6467 memory map HOW-TO
- DM6467 memory map HOW-TO
- How to troubleshoot memory problems
- abstract抽象类
- Android 获取IMEI码
- 第五周项目5 -——后缀表达式
- 基于MySQL提供的Yum repository安装MySQL5.6
- 对于三十岁啥重要
- How to increase MySQL memory limit?
- 手把手编写自己的PHP MVC框架实例教程
- 免费高清录直播的软件分享
- (学习笔记)Python BeautifulSoup4 取值部分
- 红帽rhce认证培训分析
- forward和redirect的区别
- [李景山php]简单的PHP 任务分配系统
- Android Volley完全解析(二),使用Volley加载网络图片
- C++,C#,VC,VC.net,java以及VC++有什么区别和联系?