Debugging MySQL Memory Alerts: When innodb_buffer_pool_size Isn't the Whole Story

Image
Posted on MySQL Ninjas | August 2026 Every DBA has been there. An alert fires. You SSH into the box, run free -h , and see MySQL consuming far more RAM than you configured. You double-check innodb_buffer_pool_size . It's set correctly. So where is the memory going? This is the story of debugging exactly that — on a Google Cloud c4d-standard-4 instance with 14.7 GB RAM, MySQL configured with a 7168 MB buffer pool, and mysqld RSS sitting at 10.4 GB . That's a 3.2 GB gap nobody could explain. The Setup We run a large MySQL fleet on GCP — over 200 DR replica nodes across three datacenters. As part of a buffer pool tuning project (fitting the right pool size to the right machine class), we set innodb_buffer_pool_size = 7168 MB on our c4d-standard-4 nodes (16 GB RAM, 14.7 GB usable). Shortly after, memory alerts started firing. When I looked at what was actually happening: $ ps aux | grep mysqld | awk '{print $6/1024 " MB"}' 10490 MB ...

Shell/Bash Commands Execution from MySQL Client or Stored Procedure/function


Today I am going to explain ways to execute shell or bash commands from mysql clients or stored procedure and function. There are basically 2 method to do so:
Method 1: Use MySQL Client inbuilt feature
 To run single command: \! command or system command. eg \! uptime or system command
 To get terminal \! bash or \! sh

Method 2: Deploy external plugin (lib_mysqludf_sys)
Step 1: Download lib_mysqludf_sys from github:
git clone https://github.com/mysqludf/lib_mysqludf_sys.git 
Step 2: Install libmysqlclient15-dev, for Ubuntu you can use:
apt-get install libmysqlclient15-dev 
Step 3: Note down o/p of:
mysql -uroot -pxxxx -e "select @@plugin_dir;" 
Step 4: Change directory to git clone dir.
cd lib_mysqludf_sys/
Step 5: Compile and put plugin in plugin dir
gcc -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o {value from step 3}lib_mysqludf_sys.so -fPIC 
Step 6: Create necessary functions for lib_mysqludf_sys:
mysql -uroot -pxxx mysql -e "source lib_mysqludf_sys.sql" 
Step 7: library lib_mysqludf_sys contains a number of functions that allows one to interact with the operating system.

sys_eval - executes an arbitrary command, and returns it's output eg: select sys_eval("df -h")
sys_exec - executes an arbitrary command, and returns it's exit code eg: select sys_exec("df -h")
sys_get - gets the value of an environment variable.
sys_set - create or update an environment variable.
lib_mysqludf_sys_info - information about the currently installed version of lib_mysqludf_sys.

Comments

  1. Very useful information. Thank you so much for this wonderful blog…Great work keep going.
    We are offering 1-month free trial of backup on cloud and assuring the lowest price guarantee. Contact us: +91-9971329945
    Please visit us our website:
    web hosting
    backup on cloud
    best linux web hosting services
    best windows hosting
    android cloud backup solutions

    ReplyDelete

Post a Comment

Popular posts from this blog

Azure VM Application Consistent MySQL DB Disk Snapshots

Debugging MySQL Memory Alerts: When innodb_buffer_pool_size Isn't the Whole Story

MongoDB InPlace Version Upgrade 3.4x to 3.6x