How can I limit mysqld memory consumption?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








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?










share|improve this question























  • MySQL or MariaDB?
    – NerdOfLinux
    Mar 13 at 18:09














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?










share|improve this question























  • MySQL or MariaDB?
    – NerdOfLinux
    Mar 13 at 18:09












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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 13 at 18:10









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
















  • 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










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


  • 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*


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.






share|improve this answer




















  • Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
    – NerdOfCode
    Mar 13 at 21:50










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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


  • 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*


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.






share|improve this answer




















  • Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
    – NerdOfCode
    Mar 13 at 21:50














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


  • 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*


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.






share|improve this answer




















  • Thank you for this helpful post. Although next time I suggest writing for an Ubuntu machine.
    – NerdOfCode
    Mar 13 at 21:50












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


  • 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*


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.






share|improve this answer












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


  • 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*


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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491