Bug #2631 mlockall called after dropping root permissions
Submitted: 3 Feb 2004 10:55 Modified: 7 Sep 2004 8:28
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0 OS:
Assigned to: Ramil Kalimullin CPU Architecture:Any

[3 Feb 2004 10:55] [ name withheld ]
Description:
The memlock option does not work if --user is also used to run the daemon as non-root.  The call to mlockall needs to be made before doing setuid to become non-root, else it fails for lack of permissions.

This bug was filed in Red Hat's bugzilla and I'm just passing it upstream:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=81378
AFAICS the issue is still present in MySQL 4.0.17, but the patch proposed by the original submitter no longer applies.

How to repeat:
See above link for details.
[3 Feb 2004 14:45] Dean Ellis
Verified, and additionally as written it would appear that mlockall() is not even called unless running as root, yet locked_in_memory remains true.
[19 Mar 2004 3:33] Sergei Glukhov
Fx on dev-bugs
Subj: Fix for bug2631: mlockall called after dropping root permissions
Date: 2004-03-19
[31 Mar 2004 2:01] Michael Widenius
The problem is becasue of how the database layer is designed we can only use mlockall if you are running the mysqld server as root.

The reason is that we must call mlockall() after all databases has been initialized and have allocated their memory. We can't however call set_user() after the databases has been initialized becasue then the databases & log files would be owned by the wrong user.

The MySQL documentation already states that to use this the --memlock option you must run the MySQL server as root.
[31 Mar 2004 13:02] Sergei Golubchik
another solution is being considered
[3 Sep 2004 16:49] Ramil Kalimullin
Sergei, please review my fix:
ChangeSet
  1.2008 04/09/03 19:26:11 ram@gw.mysql.r18.ru
[7 Sep 2004 8:28] Ramil Kalimullin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html