How can I limit mysqld memory consumption?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
Mysql High Memory Consumption
Recently I have migrated from Debian Server to Ubuntu server and I have noticed that mysqld
memory consumption on Ubuntu Server is ridiculously high for little to no use...
Solutions?
I was wondering if there are any ways that I can perhaps limit this memory consumption as it does put my server in a dangerously unresponsive position?
server mysql
add a comment |Â
up vote
0
down vote
favorite
Mysql High Memory Consumption
Recently I have migrated from Debian Server to Ubuntu server and I have noticed that mysqld
memory consumption on Ubuntu Server is ridiculously high for little to no use...
Solutions?
I was wondering if there are any ways that I can perhaps limit this memory consumption as it does put my server in a dangerously unresponsive position?
server mysql
MySQL or MariaDB?
â NerdOfLinux
Mar 13 at 18:09
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Mysql High Memory Consumption
Recently I have migrated from Debian Server to Ubuntu server and I have noticed that mysqld
memory consumption on Ubuntu Server is ridiculously high for little to no use...
Solutions?
I was wondering if there are any ways that I can perhaps limit this memory consumption as it does put my server in a dangerously unresponsive position?
server mysql
Mysql High Memory Consumption
Recently I have migrated from Debian Server to Ubuntu server and I have noticed that mysqld
memory consumption on Ubuntu Server is ridiculously high for little to no use...
Solutions?
I was wondering if there are any ways that I can perhaps limit this memory consumption as it does put my server in a dangerously unresponsive position?
server mysql
server mysql
edited Mar 13 at 18:10
![](https://i.stack.imgur.com/ypy8w.png?s=32&g=1)
![](https://i.stack.imgur.com/ypy8w.png?s=32&g=1)
galoget
2,1062820
2,1062820
asked Mar 13 at 18:08
NerdOfCode
1,032223
1,032223
MySQL or MariaDB?
â NerdOfLinux
Mar 13 at 18:09
add a comment |Â
MySQL or MariaDB?
â NerdOfLinux
Mar 13 at 18:09
MySQL or MariaDB?
â NerdOfLinux
Mar 13 at 18:09
MySQL or MariaDB?
â NerdOfLinux
Mar 13 at 18:09
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
I would use control groups to accomplish what you're asking.
Please read before following these instructions: I read on RedHat's documentation site that libcgroups has been deprecated recently. RedHat provides a guide for creating control groups with systemd here.
Also, in the methods described below *text* denotes a number or file name to be defined by the user.
Method 1: libcgroups (apparently deprecated)
You can install libcgroups, which contains a series of utilities for creating cgroups such as cgcreate and cgclassify, by typing sudo apt install libcgroups
. Once installed, perform the following:
- Create a cgroup called sqlgroup (or whatever you want to call it)
- Type
cgcreate -g memory,cpu:sqlgroup
- Type
- Set memory limit.
cgset -r memory.limit_in_bytes=$((*mathExpressionForDesiredLimit*)) sqlgroup
- Associate new group with the desired process to control.
- If the process is currently running, use cgclassify by typing
cgclassify -g memory,cpu:sqlgroup $(*PID of mysql process*)
- If the process is not running, you can use cgexec by typing
cgexec cpu,memory:sqlgroup *processName* *additional arguments*
- If the process is currently running, use cgclassify by typing
Method Two: Manual Configuration
You can also accomplish this manually without installing additional packages using the following (Note: You must have systemd 232 or later. systemctl --version | grep systemd
gives current version info):
mkdir /sys/fs/cgroup/memory/groupname
. This creates a folder under [...]/cgroup/memory, which specifies that the cgroup will control memory. Note: change groupname to something that corresponds to the process you want to restrict. You can name it anything. In the previous method I described the groupname was sqlgroup.- Set the memory limit for the process by creating a file under the groupname folder you created that contains the memory limit in bytes. This can be done using:
echo amount_in_bytes > /sys/fs/cgroup/memory/groupname/memory.limit_in_bytes
. Do not alter the name of memory.limit_in_bytes. - Move the PID of the process you want to restrict into the cgroup.procs file. It can be created with
echo *PID_Number* > /sys/fs/cgroup/memory/groupname/cgroup.procs
. Note: If multiple processes with different PIDs are to be restricted, you will have to enter each PID into the cpgroup.procs file manually.
More advanced configuration options regarding cgroups can be found here.
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I would use control groups to accomplish what you're asking.
Please read before following these instructions: I read on RedHat's documentation site that libcgroups has been deprecated recently. RedHat provides a guide for creating control groups with systemd here.
Also, in the methods described below *text* denotes a number or file name to be defined by the user.
Method 1: libcgroups (apparently deprecated)
You can install libcgroups, which contains a series of utilities for creating cgroups such as cgcreate and cgclassify, by typing sudo apt install libcgroups
. Once installed, perform the following:
- Create a cgroup called sqlgroup (or whatever you want to call it)
- Type
cgcreate -g memory,cpu:sqlgroup
- Type
- Set memory limit.
cgset -r memory.limit_in_bytes=$((*mathExpressionForDesiredLimit*)) sqlgroup
- Associate new group with the desired process to control.
- If the process is currently running, use cgclassify by typing
cgclassify -g memory,cpu:sqlgroup $(*PID of mysql process*)
- If the process is not running, you can use cgexec by typing
cgexec cpu,memory:sqlgroup *processName* *additional arguments*
- If the process is currently running, use cgclassify by typing
Method Two: Manual Configuration
You can also accomplish this manually without installing additional packages using the following (Note: You must have systemd 232 or later. systemctl --version | grep systemd
gives current version info):
mkdir /sys/fs/cgroup/memory/groupname
. This creates a folder under [...]/cgroup/memory, which specifies that the cgroup will control memory. Note: change groupname to something that corresponds to the process you want to restrict. You can name it anything. In the previous method I described the groupname was sqlgroup.- Set the memory limit for the process by creating a file under the groupname folder you created that contains the memory limit in bytes. This can be done using:
echo amount_in_bytes > /sys/fs/cgroup/memory/groupname/memory.limit_in_bytes
. Do not alter the name of memory.limit_in_bytes. - Move the PID of the process you want to restrict into the cgroup.procs file. It can be created with
echo *PID_Number* > /sys/fs/cgroup/memory/groupname/cgroup.procs
. Note: If multiple processes with different PIDs are to be restricted, you will have to enter each PID into the cpgroup.procs file manually.
More advanced configuration options regarding cgroups can be found here.
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
add a comment |Â
up vote
2
down vote
accepted
I would use control groups to accomplish what you're asking.
Please read before following these instructions: I read on RedHat's documentation site that libcgroups has been deprecated recently. RedHat provides a guide for creating control groups with systemd here.
Also, in the methods described below *text* denotes a number or file name to be defined by the user.
Method 1: libcgroups (apparently deprecated)
You can install libcgroups, which contains a series of utilities for creating cgroups such as cgcreate and cgclassify, by typing sudo apt install libcgroups
. Once installed, perform the following:
- Create a cgroup called sqlgroup (or whatever you want to call it)
- Type
cgcreate -g memory,cpu:sqlgroup
- Type
- Set memory limit.
cgset -r memory.limit_in_bytes=$((*mathExpressionForDesiredLimit*)) sqlgroup
- Associate new group with the desired process to control.
- If the process is currently running, use cgclassify by typing
cgclassify -g memory,cpu:sqlgroup $(*PID of mysql process*)
- If the process is not running, you can use cgexec by typing
cgexec cpu,memory:sqlgroup *processName* *additional arguments*
- If the process is currently running, use cgclassify by typing
Method Two: Manual Configuration
You can also accomplish this manually without installing additional packages using the following (Note: You must have systemd 232 or later. systemctl --version | grep systemd
gives current version info):
mkdir /sys/fs/cgroup/memory/groupname
. This creates a folder under [...]/cgroup/memory, which specifies that the cgroup will control memory. Note: change groupname to something that corresponds to the process you want to restrict. You can name it anything. In the previous method I described the groupname was sqlgroup.- Set the memory limit for the process by creating a file under the groupname folder you created that contains the memory limit in bytes. This can be done using:
echo amount_in_bytes > /sys/fs/cgroup/memory/groupname/memory.limit_in_bytes
. Do not alter the name of memory.limit_in_bytes. - Move the PID of the process you want to restrict into the cgroup.procs file. It can be created with
echo *PID_Number* > /sys/fs/cgroup/memory/groupname/cgroup.procs
. Note: If multiple processes with different PIDs are to be restricted, you will have to enter each PID into the cpgroup.procs file manually.
More advanced configuration options regarding cgroups can be found here.
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I would use control groups to accomplish what you're asking.
Please read before following these instructions: I read on RedHat's documentation site that libcgroups has been deprecated recently. RedHat provides a guide for creating control groups with systemd here.
Also, in the methods described below *text* denotes a number or file name to be defined by the user.
Method 1: libcgroups (apparently deprecated)
You can install libcgroups, which contains a series of utilities for creating cgroups such as cgcreate and cgclassify, by typing sudo apt install libcgroups
. Once installed, perform the following:
- Create a cgroup called sqlgroup (or whatever you want to call it)
- Type
cgcreate -g memory,cpu:sqlgroup
- Type
- Set memory limit.
cgset -r memory.limit_in_bytes=$((*mathExpressionForDesiredLimit*)) sqlgroup
- Associate new group with the desired process to control.
- If the process is currently running, use cgclassify by typing
cgclassify -g memory,cpu:sqlgroup $(*PID of mysql process*)
- If the process is not running, you can use cgexec by typing
cgexec cpu,memory:sqlgroup *processName* *additional arguments*
- If the process is currently running, use cgclassify by typing
Method Two: Manual Configuration
You can also accomplish this manually without installing additional packages using the following (Note: You must have systemd 232 or later. systemctl --version | grep systemd
gives current version info):
mkdir /sys/fs/cgroup/memory/groupname
. This creates a folder under [...]/cgroup/memory, which specifies that the cgroup will control memory. Note: change groupname to something that corresponds to the process you want to restrict. You can name it anything. In the previous method I described the groupname was sqlgroup.- Set the memory limit for the process by creating a file under the groupname folder you created that contains the memory limit in bytes. This can be done using:
echo amount_in_bytes > /sys/fs/cgroup/memory/groupname/memory.limit_in_bytes
. Do not alter the name of memory.limit_in_bytes. - Move the PID of the process you want to restrict into the cgroup.procs file. It can be created with
echo *PID_Number* > /sys/fs/cgroup/memory/groupname/cgroup.procs
. Note: If multiple processes with different PIDs are to be restricted, you will have to enter each PID into the cpgroup.procs file manually.
More advanced configuration options regarding cgroups can be found here.
I would use control groups to accomplish what you're asking.
Please read before following these instructions: I read on RedHat's documentation site that libcgroups has been deprecated recently. RedHat provides a guide for creating control groups with systemd here.
Also, in the methods described below *text* denotes a number or file name to be defined by the user.
Method 1: libcgroups (apparently deprecated)
You can install libcgroups, which contains a series of utilities for creating cgroups such as cgcreate and cgclassify, by typing sudo apt install libcgroups
. Once installed, perform the following:
- Create a cgroup called sqlgroup (or whatever you want to call it)
- Type
cgcreate -g memory,cpu:sqlgroup
- Type
- Set memory limit.
cgset -r memory.limit_in_bytes=$((*mathExpressionForDesiredLimit*)) sqlgroup
- Associate new group with the desired process to control.
- If the process is currently running, use cgclassify by typing
cgclassify -g memory,cpu:sqlgroup $(*PID of mysql process*)
- If the process is not running, you can use cgexec by typing
cgexec cpu,memory:sqlgroup *processName* *additional arguments*
- If the process is currently running, use cgclassify by typing
Method Two: Manual Configuration
You can also accomplish this manually without installing additional packages using the following (Note: You must have systemd 232 or later. systemctl --version | grep systemd
gives current version info):
mkdir /sys/fs/cgroup/memory/groupname
. This creates a folder under [...]/cgroup/memory, which specifies that the cgroup will control memory. Note: change groupname to something that corresponds to the process you want to restrict. You can name it anything. In the previous method I described the groupname was sqlgroup.- Set the memory limit for the process by creating a file under the groupname folder you created that contains the memory limit in bytes. This can be done using:
echo amount_in_bytes > /sys/fs/cgroup/memory/groupname/memory.limit_in_bytes
. Do not alter the name of memory.limit_in_bytes. - Move the PID of the process you want to restrict into the cgroup.procs file. It can be created with
echo *PID_Number* > /sys/fs/cgroup/memory/groupname/cgroup.procs
. Note: If multiple processes with different PIDs are to be restricted, you will have to enter each PID into the cpgroup.procs file manually.
More advanced configuration options regarding cgroups can be found here.
answered Mar 13 at 20:41
Saul Kapruac
1263
1263
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
add a comment |Â
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
â NerdOfCode
Mar 13 at 21:50
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1014659%2fhow-can-i-limit-mysqld-memory-consumption%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
MySQL or MariaDB?
â NerdOfLinux
Mar 13 at 18:09