Building and running MySQL as a local (non-root) user
Charles Roth, 16 April 2014
I occasionally need MySQL on a Linux box, on which I don't have root access.
(Oddly enough, this happens most frequently at work, where I may be allocated
a server for internal work, but root access is jealously guarded by the guardians
of the hardware.)
It's surprisingly complicated to configure a binary MySQL distribution to run
as a local user, aka in "userspace".
Oddly enough, I found it easiest to simply build MySQL from source,
with the various directories it needs pre-configured, and then run it from there.
II. Build and install
these instructions assume that MySQL is not
running on this server.
If it is
, you'll need to figure out how to tell the build not to use the
same port, typically 3306.
- Install cmake.
MySQL requires cmake.
If you don't already have cmake ("which cmake"),
you can easily download and install it from source.
- Download source from
- Unpack, e.g
tar xvfz cmake-18.104.22.168.tar.gz
- Install, e.g.:
- Add $HOME/CMAKE/bin to your PATH.
- Build MySQL.
- Download from dev.mysql.com/downloads/mysql.
At "Select Platform", choose "Source Code",
then choose "generic linux (architecture independent)".
- Unpack, e.g.
tar xvfz mysql-5.6.17.tar.gz
- Configure and prepare installation location, e.g.:
cmake -D MYSQL_DATADIR=$HOME/MySQL/data -D SYSCONFDIR=$HOME/MySQL/etc -D CMAKE_INSTALL_PREFIX=$HOME/MySQL .
(notice the trailing ".")
- Prepare base MySQL tables, e.g.:
- Start the server, and set the root password:
bin/mysqladmin -u root password 'newPassword'
- Create mysql client script.
E.g. in my $HOME/bin, I create 'mysql' containing:
Make sure it's executable, and in the PATH
(before any possibly already-installed mysql elsewhere!).
- Put the start/stop script in an easy place (or create your own),
then bounce the server and verify that you can connect to it:
cp support-files/mysql.server $HOME/bin
mysql -u root -p
- Start server at reboot.
I also like to use cron to restart MySQL at reboot.
I add something like the following to my crontab:
@reboot /home/myuser/bin/mysql.server start
- Other configuration.
There are many configuration changes that can be made to the
$HOME/MySQL/my.cnf file, that are outside the scope of this article.
See, for example,