Forum Moderators: coopster

Message Too Old, No Replies

Determine MySQL memory allocation via PHP

         

alsid

11:30 am on Oct 23, 2010 (gmt 0)

10+ Year Member



Hello!

It there a way to determine MySQL server memory allocation (for the current task or for the whole system at current time) via php. Cannot find any related php function...

Thank you.

coopster

11:37 am on Oct 27, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, alsid.

In the unlikely event your MySQL server was compiled --with-debug=full [dev.mysql.com] you can execute a MySQL status [dev.mysql.com] command/query from PHP and view some memory usage information. Or at least I believe you should see some memory usage. I believe this should show the same information as the command: mysqladmin -u username -pPassword status, but I have not tested it. I don't have a MySQL server set up for debugging, no need.

Start your reading here:
mysqladmin — Client for Administering a MySQL Server [dev.mysql.com]

But I believe you'll finally end up reading about How MySQL Uses Memory [dev.mysql.com] and ultimately find you will probably need to execute a system command like ps and parse the results. From that page ...

ps and other system status programs may report that mysqld uses a lot of memory. This may be caused by thread stacks on different memory addresses. For example, the Solaris version of ps counts the unused memory between stacks as used memory. To verify this, check available swap with swap -s. We test mysqld with several memory-leakage detectors (both commercial and Open Source), so there should be no memory leaks.


Also, check into PHP 5.3 and the The MySQL Native Driver [webmasterworld.com]. 3 new commands available that may be of interest.